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);
  • 相关阅读:
    zabbix_server调优
    zabbix图形刷新延迟解决
    ntp同步报错解决
    python3.5 字典遍历
    python3.5 append使用
    python3.5 元组
    pycharm修改代码后第一次运行不生效解决
    Intellij IDEA 使用Spring-boot-devTools无效解决办法
    TOP命令各个参数代表意义详解
    ps命令各个内容信息详解
  • 原文地址:https://www.cnblogs.com/lucika/p/4740030.html
Copyright © 2011-2022 走看看