首页 > Windows开发 > 详细

C#利用Aspose在同一个Excel文件中创建多个sheet

时间:2021-04-20 14:15:35      阅读:30      评论:0      收藏:0      [点我收藏+]

代码如下:

        private void DataGridViewExportSheet(Aspose.Cells.Worksheet sheet, DataGridView dataGridView)
        {
            int irows = dataGridView.RowCount;
            int icols = dataGridView.ColumnCount;

            for (int i = 0; i < icols; i++)
            {
                if (dataGridView.Columns[i].Visible)
                {
                    string fldName = dataGridView.Columns[i].HeaderText;
                    sheet.Cells[0, i].PutValue(fldName);
                }
            }

            for (int i = 0; i < irows; i++)
            {
                for (int j = 0; j < icols; j++)
                {
                    if (dataGridView.Columns[j].Visible)
                    {
                        if (dataGridView.Rows[i].Cells[j].Value != null)
                        {
                            sheet.Cells[i + 1, j].PutValue(dataGridView.Rows[i].Cells[j].Value.ToString());
                        }
                    }
                }
            }
        }

调用方法:

  new Aspose.Cells.License().SetLicense(new MemoryStream(Convert.FromBase64String(Key)));
  workbook = new Aspose.Cells.Workbook();
  Aspose.Cells.Worksheet sheet = workbook.Worksheets[0];
  sheet.Name = "基本信息";
  DataGridViewExportSheet(sheet, dgvzkxx);
  workbook.Save(strpath);

 

C#利用Aspose在同一个Excel文件中创建多个sheet

原文:https://www.cnblogs.com/leebokeyuan/p/14680431.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!