• <menu id="w2i4a"></menu>
  • logo Aspose中文文檔

    文檔首頁>>Aspose中文文檔>>NPOI 格式化文檔中的表格

    NPOI 格式化文檔中的表格


    Aspose.Words是一種高級Word文檔處理API,用于執(zhí)行各種文檔管理和操作任務。API支持生成,修改,轉(zhuǎn)換,呈現(xiàn)和打印文檔,而無需在跨平臺應用程序中直接使用Microsoft Word。

    Aspose API支持流行文件格式處理,并允許將各類文檔導出或轉(zhuǎn)換為固定布局文件格式和最常用的圖像/多媒體格式。

    Aspose.Words for .NET 最新下載

    Aspose.Words

    請注意,在應用表屬性之前,表中必須至少存在一行。這意味著使用DocumentBuilder構(gòu)建表時,必須在首次調(diào)用DocumentBuilder.InsertCell之后或?qū)⒌谝恍刑砑拥奖碇蠡驅(qū)⒐?jié)點直接插入到 DOM 中時完成此類格式化。

    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);
    Table table = builder.StartTable();
    builder.InsertCell();
    
    // Set the borders for the entire table.
    table.SetBorders(LineStyle.Single, 2.0, Color.Black);
    
    // Set the cell shading for this cell.
    builder.CellFormat.Shading.BackgroundPatternColor = Color.DarkGray;
    builder.Writeln("Cell #1");
    builder.InsertCell();
    
    // Specify a different cell shading for the second cell.
    builder.CellFormat.Shading.BackgroundPatternColor=Color.Blue;
    builder.Writeln("Cell #2");
    
    // End this row.
    builder.EndRow();
    
    // Clear the cell formatting from previous operations.
    builder.CellFormat.ClearFormatting();
    
    // Create the second row.
    builder.InsertCell();
    
    // Create larger borders for the first cell of this row. This will be different
    // compared to the borders set for the table.
    builder.CellFormat.Borders.Left.LineWidth=4.0;
    builder.CellFormat.Borders.Right.LineWidth=4.0;
    builder.CellFormat.Borders.Top.LineWidth=4.0;
    builder.CellFormat.Borders.Bottom.LineWidth=4.0;
    builder.Writeln("Cell #3");
    builder.InsertCell();
    
    // Clear the cell formatting from the previous cell.
    builder.CellFormat.ClearFormatting();
    builder.Writeln("Cell #4");
    doc.Save("Format Table in Document.doc");

    點擊復制

    NPOI

    // Create a new document from scratch
    XWPFDocument doc = new XWPFDocument();
    XWPFTable table = doc.CreateTable(3, 3);
    table.GetRow(1).GetCell(1).SetText("EXAMPLE OF TABLE");
    XWPFTableCell c1 = table.GetRow(0).GetCell(0);
    XWPFParagraph p1 = c1.AddParagraph(); //don't use doc.CreateParagraph
    XWPFRun r1 = p1.CreateRun();
    r1.SetText("This is test table contents");
    r1.IsBold=true;
    r1.FontFamily = "Courier";
    r1.SetUnderline(UnderlinePatterns.DotDotDash);
    r1.SetTextPosition(100);
    c1.SetColor("FF0000");
    table.GetRow(2).GetCell(2).SetText("only text");
    FileStream out1 = new FileStream("data/Format Table in Document.docx", FileMode.Create);
    doc.Write(out1);
    out1.Close();

    點擊復制

    下載運行代碼

    下載示例代碼

    掃碼咨詢


    添加微信 立即咨詢

    電話咨詢

    客服熱線
    023-68661681

    TOP
    三级成人熟女影院,欧美午夜成人精品视频,亚洲国产成人乱色在线观看,色中色成人论坛 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();