我正在尝试使用MigraDoc创建PDF文档,当表包含左缩进时,我正面临着表边框的问题 .
我将数据传递给以下函数来呈现表 .
public void AddTable(int _iNumberOfColumns, double leftInd)
{
table = section.AddTable();
if (leftInd != 0d)
{
table.Format.LeftIndent = leftInd;
}
for (int i = 0; i < _iNumberOfColumns; i++)
{
Column col = table.AddColumn();
}
}
在上面的方法中,我传递参数 leftInd
的double值 . 我认为,这是问题的原因 .
添加单元格的代码如下 . 我'm passing bool variables to decide if the cells border needs to be visible or not... (To add a row I'我只是打电话 row = table.AddRow();
)
public void AddColumn(int _iCellNum, int iColspan, double dCellWidthInPt, System.Drawing.Color color, bool bTopBorder, bool bLeftBorder, bool bBottomBorder, bool bRightBorder)
{
cell = row.Cells[_iCellNum];
if (iColspan > 0)
{
cell.MergeRight = iColspan-1;
for (int i = 0; i < iColspan; i++)
{
row.Cells[_iCellNum + i].Column.Width = new Unit(dCellWidthInPt, UnitType.Point);
}
}
else
{
cell.Column.Width = new Unit(dCellWidthInPt, UnitType.Point);
}
//bRightBorder = bLeftBorder = bTopBorder = bBottomBorder = true;
cell.Borders.Right.Visible = bRightBorder;
cell.Borders.Left.Visible = bLeftBorder;
cell.Borders.Top.Visible = bTopBorder;
cell.Borders.Bottom.Visible = bBottomBorder;
if (color!=null)
{
cell.Format.Shading.Color = new Color(color.A, color.R, color.G, color.B);
}
}
我得到以下输出: -
如果我删除左缩进,则表格正确呈现(即左缩进不会将表格边框向左移动) .
我无法更改页面的边距,因为此表是具有不同边距的文档的一部分 . 同样,我不能添加新的部分,因为这将添加一个新的页面 .
版本:Migradoc:1.32.3885.0 pdfSharp:1.32.2608.0
关于我可能遗失的任何建议?
Edit
这就是我试图使用 table.Format.LeftIndent
这是我得到的
1 回答
要缩进表格,请设置
table.Rows.LeftIndent
. 负值也有效 .正如在注释中所写,
table.Format.LeftIndent
为表格单元格中的所有段落设置默认缩进,因此它会移动文本,但不会移动边框 .