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);
  • 相关阅读:
    mysql中lock tables与unlock tables(锁表/解锁)使用总结
    php开始,html应用的一些不错收藏
    正则表达总结
    yii2 安装
    Nginx出现413 Request Entity Too Large错误解决方法
    jQuery中使用ajaxSubmit提交表单
    Go Log模块生成日志文件
    Go sync模块
    Golang html encoding解析
    Go struct tag
  • 原文地址:https://www.cnblogs.com/lucika/p/4740030.html
Copyright © 2011-2022 走看看