Table outerTable = CreateTable(doc, 3, 6, "");
///
///创建几行几列表格 Creates a new table in the document with the given dimensions and text in each cell.
///
private Table CreateTable(Document doc, int rowCount, int cellCount, string cellText)
{
Table table = new Table(doc);
// Create the specified number of rows.
for (int rowId = 1; rowId <= rowCount; rowId++)
{
Row row = new Row(doc);
table.AppendChild(row);
// Create the specified number of cells for each row.
for (int cellId = 1; cellId <= cellCount; cellId++)
{
Cell cell = new Cell(doc);
//需要设置一下这个值
Paragraph p = new Paragraph(doc);
p.AppendChild(new Run(doc, ""));
p.ParagraphFormat.Style.Font.Size = 10;
p.ParagraphFormat.Style.Font.Name = "Arial";
p.ParagraphFormat.Alignment = ParagraphAlignment.Center;
p.ParagraphFormat.LineSpacingRule = LineSpacingRule.Multiple; // 设置段落
p.ParagraphFormat.LineSpacing = 12; // 设置段落 默认给的是15.6磅**
cell.AppendChild(p);
// cell.CellFormat.Shading.BackgroundPatternColor = 颜色 ;
cell.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
// cell.FirstParagraph.AppendChild(new Run(doc, cellText));
row.AppendChild(cell);
}
}
return table;
}
p.ParagraphFormat.Alignment = ParagraphAlignment.Center;
p.ParagraphFormat.LineSpacingRule = LineSpacingRule.Multiple; // 设置段落
p.ParagraphFormat.LineSpacing = 12; // 设置段落 默认给的是15.6磅
cell.AppendChild(p);
cell.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
cell.FirstParagraph.AppendChild(new Run(doc,“test”));
row.AppendChild(cell);
p.ParagraphFormat.LineSpacingRule = LineSpacingRule.Multiple; // 设置段落
p.ParagraphFormat.LineSpacing = 12; // 设置段落 默认给的是15.6磅
为何段落设置不起作用