我有一张正在打印的桌子。我已经为所有单元格添加了边框,但是当表格进入/退出新页面时我遇到了问题。然后根据每个单元格消耗的可用空间移动/停留边界。是否可以将此行依赖于sted?
灰线是页面移位。
foreach (Task task in TasksToShow)
{
myTable.RowGroups[0].Rows.Add(new TableRow());
currentRow = myTable.RowGroups[0].Rows[rowCount++];
currentRow.Cells.Add(new TableCell(new Paragraph(new Run(task.TaskID.ToString()))));
currentRow.Cells.Add(new TableCell(new Paragraph(new Run(task.TaskName))));
currentRow.Cells.Add(new TableCell(new Paragraph(new Run(task.TaskResponsible))));
currentRow.Cells.Add(new TableCell(new Paragraph(new Run(task.TaskResponsibleDepartment))));
currentRow.Cells.Add(new TableCell(new Paragraph(new Run(task.Category))));
currentRow.Cells.Add(new TableCell(new Paragraph(new Run(task.Status))));
currentRow.Cells.Add(new TableCell(new Paragraph(new Run(task.Priority.ToString()))));
currentRow.Cells.Add(new TableCell(new Paragraph(new Run(task.StartDate.ToString("dd/MM/yy")))));
currentRow.Cells.Add(new TableCell(new Paragraph(new Run(task.ActualHours.TotalHours.ToString() + "h"))));
currentRow.Cells.Add(new TableCell(new Paragraph(new Run(task.EstimatedHours.TotalHours.ToString() + "h"))));
currentRow.Cells.Add(new TableCell(new Paragraph(new Run(task.EstimatedDeploymentDate.ToString("dd/MM/yy")))));
currentRow.Cells.Add(new TableCell(new Paragraph(new Run(task.DesiredImplementationDate.ToString("dd/MM/yy")))));
currentRow.Cells.Add(new TableCell(new Paragraph(new Run(task.APP.StartDate.ToString("dd/MM/yy")))));
currentRow.Cells.Add(new TableCell(new Paragraph(new Run(task.APP.EstimatedHours.TotalHours.ToString() + "h"))));
currentRow.Cells.Add(new TableCell(new Paragraph(new Run(task.APP.ActualHours.TotalHours.ToString() + "h"))));
currentRow.Cells.Add(new TableCell(new Paragraph(new Run(task.IN.StartDate.ToString("dd/MM/yy")))));
currentRow.Cells.Add(new TableCell(new Paragraph(new Run(task.IN.EstimatedHours.TotalHours.ToString() + "h"))));
currentRow.Cells.Add(new TableCell(new Paragraph(new Run(task.IN.ActualHours.TotalHours.ToString() + "h"))));
currentRow.Cells.Add(new TableCell(new Paragraph(new Run(task.SIS.StartDate.ToString("dd/MM/yy")))));
currentRow.Cells.Add(new TableCell(new Paragraph(new Run(task.SIS.EstimatedHours.TotalHours.ToString() + "h"))));
currentRow.Cells.Add(new TableCell(new Paragraph(new Run(task.SIS.ActualHours.TotalHours.ToString() + "h"))));
currentRow.Cells.Add(new TableCell(new Paragraph(new Run(task.Tags))));
currentRow.FontSize = 10;
currentRow.FontWeight = FontWeights.Normal;
for (int n = 0; n < currentRow.Cells.Count; n++ )
{
currentRow.Cells[n].BorderThickness = new Thickness(1, 1, 1, 1);
currentRow.Cells[n].BorderBrush = Brushes.Black;
}
}
还有一种方法可以使单元格宽度取决于最大的单元格,而不仅仅是使所有单元格的宽度相同吗?
希望你能提供帮助。
答案 0 :(得分:2)
我已经找到了一个解决方案,至少让它看起来一直都是一样,但我还没有完全满意。我刚刚将最后一个for循环中的thikness改为:
for (int n = 0; n < currentRow.Cells.Count; n++ )
{
currentRow.Cells[n].BorderThickness = new Thickness(0, 2, 1, 0);
currentRow.Cells[n].BorderBrush = Brushes.Black;
}
答案 1 :(得分:0)
最好在和表格的所有单元格上添加边框。如果表格没有边框,则表格边框处单元格的边框只有网格线宽的一半。
同一行中2个单元格之间的网格线宽度由左侧单元格的单元格边界宽度加上右侧单元格的单元格边界宽度组成。如果单元格没有邻居,则网格宽度仅是其他网格线的一半。为表格添加边框会添加不存在的邻居的边框。
table.BorderBrush = Brushes.Black,
table.BorderThickness = new Thickness(.5)
cell.BorderBrush = Brushes.Black,
cell.BorderThickness = new Thickness(.5)
我知道,这不能解决您的问题,但是至少网格线看起来更好。