我用下面的代碼出口臨時數據網格PDF,如何使用c#在gridview中設置字體顏色和大小?
System.Data.DataTable dt = new System.Data.DataTable();
CDbAccess db = new CDbAccess();
IDbConnection conn = db.GetConnectionInterface();
conn.Open();
IDbCommand cmd = db.GetCommandInterface(str);
IDbDataAdapter da = db.GetDataAdapterInterface(cmd);
da.SelectCommand = cmd;
DataSet ds = new DataSet();
try
{
da.SelectCommand = cmd;
da.Fill(ds);
dt = ds.Tables[0];
}
catch (Exception ex)
{
throw ex;
}
finally
{
conn.Close();
// da.Dispose();
conn.Dispose();
}
GridView GridView1 = new GridView();
GridView1.AllowPaging = false;
GridView1.DataSource = dt;
GridView1.DataBind();
GridView1.HeaderStyle.BackColor = System.Drawing.Color.DeepSkyBlue;
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition",
"attachment;filename=BugReport.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView1.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
,輸出爲找差,所以,我需要對齊輸出。
而我只是想將字體顏色和字體大小設置爲特定的列。
如何使用C#設置它?
之前,你得太遠,從'iTextSharp的HTMLWorker'被認爲是過時而偏愛'XMLWorker'。前者對CSS的支持幾乎爲零,並且具有更多的HTML解析器。我強烈建議切換到'XMLWorker'。 –