好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

C#使用DocumentFormat.OpenXml设置表及表格的宽度与调试

C#使用DocumentFormat.OpenXml设置表及表格的宽度与调试

using DocumentFormat.OpenXml;

using DocumentFormat.OpenXml.Packaging;

using DocumentFormat.OpenXml.Wordprocessing;

// 创建 Word 文档

using (WordprocessingDocument doc = WordprocessingDocument.Create("output.docx", WordprocessingDocumentType.Document))

{

    MainDocumentPart mainPart = doc.AddMainDocumentPart();

    mainPart.Document = new Document();

    Body body = mainPart.Document.AppendChild(new Body());

    // 创建表格并设置宽度

    Table table = new Table();

    table.AppendChild(new TableProperties

    {

        TableWidth = new TableWidth { Width = "5000", Type = TableWidthUnitValues.Dxa }

    });

    // 定义列宽

    TableGrid grid = new TableGrid();

    grid.Append(new GridColumn { Width = "2000" }, new GridColumn { Width = "3000" });

    table.Append(grid);

    // 添加行并设置行高

    TableRow row = new TableRow();

    row.AppendChild(new TableRowProperties

    {

        Height = new Height { Val = 500, HeightType = HeightRuleValues.Exact }

    });

    // 添加单元格

    row.Append(new TableCell(), new TableCell());

    table.Append(row);

    body.Append(table);

    mainPart.Document.Save();

}


查看更多关于C#使用DocumentFormat.OpenXml设置表及表格的宽度与调试的详细内容...

  阅读:57次