本文将介绍如何使用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")
效果图: