zoukankan      html  css  js  c++  java
  • Aspose.Words 随笔

    //加载文档

     Document doc = new Document(Server.MapPath("~/ExportTemplate/CLAAS/ServiceReport.doc"));

    //保存

    SetData(doc);

    doc.Save(Page.Response, "C010.doc", ContentDisposition.Attachment, null);
    doc.Clone();

    private void SetData(Document doc)
    {

    DocumentBuilder builder = new DocumentBuilder(doc);
    DataTable products = GetTable(); //数据源
    builder.MoveToDocumentEnd();
    // 下划线不设置
    builder.Font.Underline=Underline.None;
    //开始表格
    Aspose.Words.Tables.Table table = builder.StartTable();

    builder.RowFormat.Alignment = RowAlignment.Center;
    builder.CellFormat.Borders.LineStyle = LineStyle.Single;



    List<string> listcolumn = new List<string>(products.Columns.Count);
    for (var i = 0; i < products.Columns.Count; i++)
    {
    listcolumn.Add(products.Columns[i].ColumnName.Trim());
    if (i == 0)
    {
    //添加表格
    builder.InsertCell();
    builder.Write("维修信息:");
    //对其方式
    builder.CellFormat.HorizontalMerge = CellMerge.Previous;
    }
    else
    {
    builder.InsertCell();
    builder.Write("");
    builder.CellFormat.HorizontalMerge = CellMerge.None;
    }

    }
    builder.EndRow();
    //表格对其方式
    table.AutoFit(Aspose.Words.Tables.AutoFitBehavior.AutoFitToWindow);

    #region##循环表头
    foreach (string HeadName in listcolumn)
    {
    builder.InsertCell();
    builder.Write(HeadName);


    }
    builder.EndRow();

    #endregion

    #region##循环数据
    foreach (DataRow ro in products.Rows)
    {
    foreach (string HeadName in listcolumn)
    {
    builder.InsertCell();
    builder.Write(ro[HeadName].ToString());

    }
    builder.EndRow();
    }
    #endregion


    builder.EndTable();

  • 相关阅读:
    Struts2标签库
    ognl表达式
    Struts2拦截器
    Struts2文件上传与下载
    Swoft2.x 小白学习笔记 (四) --- RPC
    Swoft2.x 小白学习笔记 (三) --- Task、协程
    Swoft2.x 小白学习笔记 (二) --- mysql、redis
    Swoft2.x 小白学习笔记 (一) ---控制器
    Tornado WebSocket简单聊天
    用python实现的21点游戏
  • 原文地址:https://www.cnblogs.com/Andy-Blog/p/6443345.html
Copyright © 2011-2022 走看看