【问题标题】:How to format all Migradoc Table's Cells at once?如何一次格式化所有 Migradoc Table 的单元格?
【发布时间】:2021-08-16 01:08:14
【问题描述】:

我正在使用 Migradoc 创建一个表格,我想为所有单元格设置阴影颜色和单元格边框。

此时我只能逐个单元格地做到这一点:

        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;

如果是在循环里面,就不会那么痛苦了,但是我所有的行都是一一创建的。

如何将这些属性设置为表格中的 ALL CELLS?

【问题讨论】:

  • “但是我的所有行都是一一创建的”是什么意思?这如何阻止您使用循环?
  • @Sweeper 我的意思是每一行都不是在循环中创建的,所以对于每一行,我必须以这种方式设置单元格格式。我想知道是否有办法为整个表格设置一次单元格格式。

标签: c# pdfsharp migradoc


【解决方案1】:

你可以混合RowsColumnsStyle来实现你想要的:

        // 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

【讨论】:

  • 谢谢哈桑...我自己太复杂了:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多