zoukankan      html  css  js  c++  java
  • C#利用Aspose在同一个Excel文件中创建多个sheet

    代码如下:

            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);
    本博客有部分内容来自网络,如有问题请联系:hebeilijianghua@qq.com,并注明来自博客园。
  • 相关阅读:
    构造函数详解
    左值和左值引用、右值和右值引用
    Lambda函数
    std::thread详解
    运算符重载
    友元函数和友元类
    xadmin list_filter 外键数据不显示
    中缀表达式转后缀表达式
    Centos 7 minimal 联网
    python 运用三目判断对象中多个属性 有且非空
  • 原文地址:https://www.cnblogs.com/leebokeyuan/p/14680431.html
Copyright © 2011-2022 走看看