pdf表格

时间:2019-03-05 11:49:57

标签: c# aspose aspose-cells aspose.pdf

我添加了一个包含两行两列的表,并为所有单元格设置了边框。但它仅显示第一列的边框

示例代码如下

  

var tableestdet =新表                   {                       ColumnWidths =“ 120,120”,                       保证金=新的MarginInfo {顶部= 40,左侧= 10},

               DefaultCellBorder = new BorderInfo((int)BorderSide.All, 1F),
            };
            tableestdet.DefaultCellTextInfo = new TextInfo { Alignment = AlignmentType.Center };
            var estdet1 = tableestdet.Rows.Add();
            estdet1.DefaultRowCellPadding = new MarginInfo { Top = 5, Bottom = 5 };
            var req=estdet1.Cells.Add("Requested By:");
           var estde=estdet1.Cells.Add("Entered By:");
            var estdet2 = tableestdet.Rows.Add();               
            estdet2.DefaultCellTextInfo = new TextInfo
            {                 
                FontSize = 8,
                Alignment = AlignmentType.Center
            };
            estdet2.DefaultRowCellPadding = new MarginInfo { Top = 5, Bottom = 5 };
            estdet2.Cells.Add(Requestedby);
           estdet2.Cells.Add(CustomerName);
           sec1.Paragraphs.Add(tableestdet);

1 个答案:

答案 0 :(得分:0)

我们注意到您正在使用API​​的过时版本,因此请升级到.NET 19.2的Aspose.PDF,这是该API的最新可用版本,因为它包含更多功能和错误修复。您可以使用以下代码段在PDF文档的页面上添加表格,同时为所有单元格设置边框。

// Load source PDF document
Aspose.Pdf.Document document = new Aspose.Pdf.Document();
// Add a page to the document
Page page = document.Pages.Add();
// Initializes a new instance of the Table
Aspose.Pdf.Table table = new Aspose.Pdf.Table();
// Set the table border color as LightGray
table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
// Set the border for table cells
table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
// Create a loop to add 10 rows
for (int row_count = 1; row_count <= 10; row_count++)
{
    // Add row to table
    Aspose.Pdf.Row row = table.Rows.Add();
    // Add table cells
    row.Cells.Add("Column (" + row_count + ", 1)");
    row.Cells.Add("Column (" + row_count + ", 2)");
}
// Add table object to first page of input document
page.Paragraphs.Add(table);
// Save updated document containing table object
document.Save(dataDir + "Table_19.2.pdf");

已随附生成的PDF文档,以供您参考Table19.2.pdf。如果您需要任何进一步的帮助,请随时告诉我们。

PS::我与Aspose一起担任开发人员推广人员。