如何一次格式化所有 Migradoc Table 的单元格?
How to format all Migradoc Table's Cells at once?
我正在使用 Migradoc 创建 Table,我想设置所有单元格的底纹颜色和单元格边框。
此时我只能逐个单元地进行:
var tableRow = table.AddRow();
table.Cells[0].Shading.Color = Colors.LightBlue;
table.Cells[0].Format.LeftIndent = 1;
table.Cells[0].Borders.Color = Colors.White;
table.Cells[0].Borders.Width = 4;
table.Cells[1].Shading.Color = Colors.LightBlue;
table.Cells[1].Format.LeftIndent = 1;
table.Cells[1].Borders.Color = Colors.White;
table.Cells[1].Borders.Width = 4;
如果它在一个循环中,它不是那么痛苦,但我所有的行都是一一创建的。
如何将这些属性设置为 table 中的所有单元格?
您可以混合使用 Rows
、Columns
和 Style
来实现您想要的效果:
// Create a new style called Table based on style Normal
Style style = document.Styles.AddStyle("Table", "Normal"); //this is optional, you can have your own style :)
style.Font.Name = "Verdana";
style.Font.Name = "Times New Roman";
style.Font.Size = 9;
Table table = new Table();
table.Style = "Table";
table.Rows.LeftIndent = -1; //to indent all the rows
table.Columns.Width = 4; //width of all the columns
table.Borders.Color = Colors.White; //color of all the border
table.Shading.Color = Colors.LightBlue; //all the cells table shading color
我正在使用 Migradoc 创建 Table,我想设置所有单元格的底纹颜色和单元格边框。
此时我只能逐个单元地进行:
var tableRow = table.AddRow();
table.Cells[0].Shading.Color = Colors.LightBlue;
table.Cells[0].Format.LeftIndent = 1;
table.Cells[0].Borders.Color = Colors.White;
table.Cells[0].Borders.Width = 4;
table.Cells[1].Shading.Color = Colors.LightBlue;
table.Cells[1].Format.LeftIndent = 1;
table.Cells[1].Borders.Color = Colors.White;
table.Cells[1].Borders.Width = 4;
如果它在一个循环中,它不是那么痛苦,但我所有的行都是一一创建的。
如何将这些属性设置为 table 中的所有单元格?
您可以混合使用 Rows
、Columns
和 Style
来实现您想要的效果:
// Create a new style called Table based on style Normal
Style style = document.Styles.AddStyle("Table", "Normal"); //this is optional, you can have your own style :)
style.Font.Name = "Verdana";
style.Font.Name = "Times New Roman";
style.Font.Size = 9;
Table table = new Table();
table.Style = "Table";
table.Rows.LeftIndent = -1; //to indent all the rows
table.Columns.Width = 4; //width of all the columns
table.Borders.Color = Colors.White; //color of all the border
table.Shading.Color = Colors.LightBlue; //all the cells table shading color