如何在C#中的itextsharp-pdf中实现特定单元格的rowspan



我需要将数据从gridview导出为pdf。我正在使用itextsharp来实现这一点。然而,我有一种技巧,如果某些单元格中的值相同,我必须将数据显示为分组。我可以在gridview中进行分组,但无法在itextsharp pdf中复制分组。因此,如果行单元格中的值相同,我想将行跨度更改为大于1。例如,如果第1行中的单元格1与第2行中单元格1的值相同,则该值不应重复,而第1行单元格1的行跨度应更改并跨度为2行。如何使用itextsharp将其导出为pdf?

ITextSharp中有许多行span的例子http://forums.asp.net/t/1953696.aspx?how+to+create+a+pdf+with+rowspan+and+colspan+:

using iTextSharp.text;
using iTextSharp.text.pdf;
Document doc1 = new Document(iTextSharp.text.PageSize.A4, 10, 10, 42, 35);;
FileStream fs1;
PdfWriter wri1;
fs1 = new FileStream("C:\1.pdf", FileMode.Create, FileAccess.ReadWrite);
//Create Document class object and set its size to letter and give space left, right, Top, Bottom Margin
wri1 = PdfWriter.GetInstance(doc1, fs1);
doc1.Open();
PdfPTable t = new PdfPTable(4);
t.AddCell(new PdfPCell(new Phrase("RepGroup Logo")) { Rowspan = 9 });
t.AddCell(new PdfPCell(new Phrase("CID")));
t.AddCell(new PdfPCell(new Phrase("CID-Val")));
t.AddCell(new PdfPCell(new Phrase("Ven Logo")) { Rowspan = 9 });
t.AddCell(new PdfPCell(new Phrase("CPO")));
t.AddCell(new PdfPCell(new Phrase("CPO-Val")));
t.AddCell(new PdfPCell(new Phrase("Order Status")));
t.AddCell(new PdfPCell(new Phrase("Confirmed")));
t.AddCell(new PdfPCell(new Phrase("Order Date")));
t.AddCell(new PdfPCell(new Phrase("10/02/2013")));
t.AddCell(new PdfPCell(new Phrase("Ship Date")));
t.AddCell(new PdfPCell(new Phrase("12/01/2013")));
t.AddCell(new PdfPCell(new Phrase("Back Orders")));
t.AddCell(new PdfPCell(new Phrase("Accepted")));
t.AddCell(new PdfPCell(new Phrase("Ship Via")));
t.AddCell(new PdfPCell(new Phrase("Best Way")));
t.AddCell(new PdfPCell(new Phrase("Terms")));
t.AddCell(new PdfPCell(new Phrase("CC")));
doc1.Add(t);
doc1.Close();
Process myProcess = new Process();
myProcess.StartInfo.FileName = "acroRd32.exe"; //not the full application path
myProcess.StartInfo.Arguments = "C:\1.pdf";   // "/A "page=2=OpenActions" C:\example.pdf";
myProcess.Start();

其他链接:行还是嵌套?创建一个itextsharp表,http://developers.itextpdf.com/examples/tables/colspan-and-rowspan.

最新更新