标签:write file iter ase ntc alt arp files highlight

public static bool ToPdf(DataTable dt, string filepath, string fileName)
{
Document document = new Document();
PdfWriter.GetInstance(document, new FileStream(filepath + fileName, FileMode.Create));
document.Open();
BaseFont bfChinese = BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
iTextSharp.text.Font fontChinese = new iTextSharp.text.Font(bfChinese, 12, iTextSharp.text.Font.NORMAL, Color.BLACK);
PdfPTable table = new PdfPTable(dt.Columns.Count);
for (int i = 0; i < dt.Rows.Count; i++)
{
if (i == 0)
{
for (int j = 0; j < dt.Columns.Count; j++)
{
table.AddCell(new Phrase(dt.Columns[j].ToString(), fontChinese));
}
}
for (int j = 0; j < dt.Columns.Count; j++)
{
table.AddCell(new Phrase(dt.Rows[i][j].ToString(), fontChinese));
}
}
document.Add(table);
document.Close();
return true;
}
标签:write file iter ase ntc alt arp files highlight
原文地址:http://www.cnblogs.com/qifei-jia/p/7753519.html