本文整理匯總了C#中iTextSharp.text.pdf.PdfPTable.GetRows方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfPTable.GetRows方法的具體用法?C# PdfPTable.GetRows怎麽用?C# PdfPTable.GetRows使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類iTextSharp.text.pdf.PdfPTable
的用法示例。
在下文中一共展示了PdfPTable.GetRows方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Index
public ActionResult Index()
{
var doc = new Document();
doc.AddTitle("PDF Sales Report");
string path = "../../PDFReports";
PdfWriter.GetInstance(doc, new FileStream(path + "/Doc.pdf", FileMode.Create));
PdfPTable table = new PdfPTable(5);
PdfPCell cell = new PdfPCell();
PdfPCell firstCell = new PdfPCell();
firstCell.Phrase = new Phrase("Aggregated Sales Report");
firstCell.Colspan = 5;
table.AddCell(firstCell);
table.CompleteRow();
cell.Phrase = new Phrase("Product");
table.AddCell(cell);
cell.Phrase = new Phrase("Quantity");
table.AddCell(cell);
cell.Phrase = new Phrase("Unit Price");
table.AddCell(cell);
cell.Phrase = new Phrase("Location");
table.AddCell(cell);
cell.Phrase = new Phrase("Sum");
table.AddCell(cell);
/////////////////
SqlConnection con = new SqlConnection("Database=.;Initial Catalog=Supermarket;Integrated Security=true");
con.Open();
using (con)
{
SqlCommand com = new SqlCommand("SELECT * FROM Productss", con);
SqlDataReader reader = com.ExecuteReader();
decimal totalSum = 0;
while (reader.Read())
{
string productName = (string)reader[1];
string quantity = (string)reader[2];
decimal price = (decimal)reader[3];
string location = (string)reader[4];
decimal sum = (decimal)reader[5];
totalSum += sum;
cell.Phrase = new Phrase(productName);
table.AddCell(cell);
cell.Phrase = new Phrase(quantity);
table.AddCell(cell);
cell.Phrase = new Phrase(price.ToString());
table.AddCell(cell);
cell.Phrase = new Phrase(location);
table.AddCell(cell);
cell.Phrase = new Phrase(sum.ToString());
table.AddCell(cell);
}
var rows = table.GetRows(0, 4);
for (int i = 3; i < rows.Count; i++)
{
var row = table.GetRow(i);
var cols = row.GetCells();
foreach (var col in cols)
{
Console.Write(col.Phrase.Content + " ");
}
Console.WriteLine();
}
}
doc.Open();
doc.Add(table);
doc.Close();
return Redirect("http://localhost:20144/pdfreports/doc.pdf");
}