本文将介绍如何使用Spire.PDF删除PDF Grid中的行和列。
C#
//创建PdfDocument实例
PdfDocument doc = new PdfDocument();
//添加一页
PdfPageBase page = doc.Pages.Add();
//创建PDF grid
PdfGrid grid = new PdfGrid();
//设置单元格内容和边框之间的距离
grid.Style.CellPadding = new PdfPaddings(3, 3, 1, 1);
//添加3行和4列
PdfGridRow row1 = grid.Rows.Add();
PdfGridRow row2 = grid.Rows.Add();
PdfGridRow row3 = grid.Rows.Add();
grid.Columns.Add(4);
//设置列宽
foreach (PdfGridColumn column in grid.Columns)
{
column.Width = 60f;
}
//写入数据到单元格
for (int i = 0; i < grid.Columns.Count; i++)
{
row1.Cells[i].Value = String.Format("column{0}", i + 1);
row2.Cells[i].Value = "a";
row3.Cells[i].Value = "b";
}
//删除第二行
grid.Rows.RemoveAt(1);
//删除第二列
grid.Columns.RemoveAt(1);
//在页面的指定位置绘制grid
grid.Draw(page, new PointF(0, 20));
//保存文件
doc.SaveToFile("Output.pdf");
VB.NET
'创建PdfDocument实例
Dim doc As New PdfDocument()
'添加一页
Dim page As PdfPageBase = doc.Pages.Add()
'创建PDF grid
Dim grid As New PdfGrid()
'设置单元格内容和边框之间的距离
grid.Style.CellPadding = New PdfPaddings(3, 3, 1, 1)
'添加3行和4列
Dim row1 As PdfGridRow = grid.Rows.Add()
Dim row2 As PdfGridRow = grid.Rows.Add()
Dim row3 As PdfGridRow = grid.Rows.Add()
grid.Columns.Add(4)
'设置列宽
For Each column As PdfGridColumn In grid.Columns
column.Width = 60F
Next
'写入数据到单元格
For i As Integer = 0 To grid.Columns.Count - 1
row1.Cells(i).Value = [String].Format("column{0}", i + 1)
row2.Cells(i).Value = "a"
row3.Cells(i).Value = "b"
Next
'删除第二行
grid.Rows.RemoveAt(1)
'删除第二列
grid.Columns.RemoveAt(1)
'在页面的指定位置绘制grid
grid.Draw(page, New PointF(0, 20))
'保存文件
doc.SaveToFile("Output.pdf")
效果图: