我试图用MigraDoc创建一个表。我希望它看起来像这样: This is how the table should look
相反,我只是得到这个: This is the table I'm getting
文字太靠近边界了。缩进缺失。我试过了
table.Format.LeftIndent = 0.2;
和
table.Format.LeftIndent = "0,2cm";
为所有表格单元格设置缩进。但它没有用。如何实现所有表格单元的缩进?
这是我完整的测试方法:
private Document debugMigraDocTable()
{
Document document = setupDocument();
Section sectionProtocolHeader = document.AddSection();
Paragraph measValueParagraph = sectionProtocolHeader.AddParagraph("Measurement");
Table table = sectionProtocolHeader.AddTable();
table.Format.LeftIndent = 0.8;
// Table header
Column column = table.AddColumn("1,2cm");
column = table.AddColumn("1,7cm");
column = table.AddColumn("1,7cm");
column = table.AddColumn("1,2cm");
column = table.AddColumn("1,7cm");
column = table.AddColumn("1,7cm");
Row row = table.AddRow();
row.HeadingFormat = true;
row.Format.Alignment = ParagraphAlignment.Center;
row.Format.Font.Bold = true;
row.Cells[0].AddParagraph("Key");
row.Cells[1].AddParagraph("Value 1");
row.Cells[2].AddParagraph("Value 2");
row.Cells[3].AddParagraph("Key");
row.Cells[4].AddParagraph("Value 1");
row.Cells[5].AddParagraph("Value 2");
// Table data
row = table.AddRow();
row.Cells[0].AddParagraph("1");
row.Cells[1].AddParagraph("1,13");
row.Cells[2].AddParagraph("");
row.Cells[3].AddParagraph("33");
row.Cells[4].AddParagraph("0,84");
row.Cells[5].AddParagraph("");
row = table.AddRow();
row.Cells[0].AddParagraph("2");
row.Cells[1].AddParagraph("1,19");
row.Cells[2].AddParagraph("");
row.Cells[3].AddParagraph("34");
row.Cells[4].AddParagraph("1,35");
row.Cells[5].AddParagraph("");
row = table.AddRow();
row.Cells[0].AddParagraph("3");
row.Cells[1].AddParagraph("1,01");
row.Cells[2].AddParagraph("");
row.Cells[3].AddParagraph("35");
row.Cells[4].AddParagraph("1,28");
row.Cells[5].AddParagraph("");
return document;
}
对于预览和打印,我将其渲染为RTF:
Document document = debugMigraDocTable();
RtfDocumentRenderer rtfRenderer = new RtfDocumentRenderer();
string rtf = rtfRenderer.RenderToString(document, Path.GetTempPath());