2014-07-08 52 views
0

我用下面的代碼出口臨時數據網格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#設置它?

+0

之前,你得太遠,從'iTextSharp的HTMLWorker'被認爲是過時而偏愛'XMLWorker'。前者對CSS的支持幾乎爲零,並且具有更多的HTML解析器。我強烈建議切換到'XMLWorker'。 –

回答

1

列屬性引用的列在網格視圖設置,如果你想在一個特定的行,然後到剛剛訪問目標列:

GridView1.Rows[0].Cells[0].ControlStyle.Font.Size = 40; 
+0

如何設置它對於整個Gridview? – Sam1604

+0

您直接在Gridview中設置它.G

相關問題