我正在生成一个流程文档,该文档具有一个document.table实例作为一个块添加到该文档中。 我使用本教程here
制作了表格我正在尝试设置表格的第二组行,以使文本在单元格的右侧对齐,同时使其他组行居中。
我可以使用table1.TextAlignment = TextAlignment.Right;
设置整个表的对齐方式,但是我希望仅设置一组行,行或单个单元格以使文本对齐。
这是我的代码
FlowDocument doc = new FlowDocument();
doc.TextAlignment = TextAlignment.Center;
doc.FontFamily = new FontFamily("Century Gothic");
Table table1 = new Table();
table1.TextAlignment = TextAlignment.Center;
doc.Blocks.Add(table1);
int numberOfColumns = 12;
for (int i = 0; i < numberOfColumns; i++)
{
table1.Columns.Add(new TableColumn());
}
table1.Columns[0].Width = new GridLength(125);
//Header row group
table1.RowGroups.Add(new TableRowGroup());
table1.RowGroups[0].Rows.Add(new TableRow());
TableRow currentRow = table1.RowGroups[0].Rows[0];
currentRow.Cells.Add(new TableCell(new Paragraph(new
Run("Header 1"))));
currentRow.Cells[0].ColumnSpan = numberOfColumns;
table1.RowGroups[0].Rows.Add(new TableRow());
currentRow = table1.RowGroups[0].Rows[1];
currentRow.Cells.Add(new TableCell(new Paragraph(new
Run("Header 2"))));
currentRow.Cells[0].ColumnSpan = numberOfColumns;
//Main body
table1.RowGroups.Add(new TableRowGroup());
for (int i = 0; i < list.Count; i++)
{
table1.RowGroups[1].Rows.Add(new TableRow());
currentRow = table1.RowGroups[1].Rows[i];
currentRow.Cells.Add(new TableCell(new Paragraph(new Run(Time))));
//Rest of the columns here (These columns need right text alignment)
}
I have found this,但是当我尝试执行此操作currentRow.Cells.Add(new TableCell(new Paragraph(new Run(Time)).TextAlignment = TextAlignment.Right));
时出现此错误
无法从'System.Windows.TextAlignment'转换为'System.Windows.Documents.Block'
有人有解决方案或替代方案吗?