zoukankan      html  css  js  c++  java
  • aspose.Cells 导出Excel

    aspose

    aspse.Cells可以操作Excel,且不依赖于系统环境。

    使用模板,通过绑定输出数据源

    这种适合于对格式没有特别要求的,直接绑定数据源即可。和数据绑定控件差不多。

    WorkbookDesigner designer = new WorkbookDesigner();
    designer.Open(templetpath);
    dt.TableName = tablename;
    designer.SetDataSource(dt);
    designer.SetDataSource("title", title);
    designer.Process();
    designer.Workbook.Save(filename);

    如上,使用DataTable作为填充数据源。

     通过代码逐行输出

    对个数有特别要求的,灵活性强。可以完成单元格的合并计算等。

    第一步,Workbook

     Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook();

    如果使用模板,可以进一步打开模板。

    wb.Open(templetepath);

    第二步,Worksheet

    Aspose.Cells.Worksheet sheet = wb.Worksheets[0];

    第三步,写入数据

     sheet.Cells[row, column].PutValue(value);

    输出图片

    var pictures = sheet.Pictures;
    /*插入图片*/ pictures.Add(upperLeftRow, upperLeftColumn,
    new System.IO.MemoryStream(byte[])); /*设置图片格式,与单元格宽度和高度*/
    pictures[pictures.Count
    - 1].Placement = PlacementType.FreeFloating; sheet.Cells.SetRowHeightPixel(rowIndex, pictures[pictures.Count - 1].Height); sheet.Cells.SetColumnWidthPixel(column, width);
  • 相关阅读:
    总结报告的感想
    第14、15週PTA題目的處理
    PTA題目的處理(三)
    PTA题目的處理(四)
    PTA題目的處理(二)
    PTA題目的處理(一)
    國慶和中秋的學習成果
    剛進入大學一個月的總結和作業
    【接口平台】too many values to unpack
    【接口平台】生成静态模拟数据
  • 原文地址:https://www.cnblogs.com/lucika/p/4740030.html
Copyright © 2011-2022 走看看