我想創建一個按鈕選項,它將整個數據列表轉換爲pdf文件。正如任何人在asp.net中做到的一樣?請你可以展示一個例子或以正確的方式指導我。作爲pdf轉換/導出C#datalist控件/(html頁面)
0
A
回答
0
您的解決方案剛剛發現的代碼片段一個人張貼在論壇上,雖然我可能跟別人
再分享:EXPORT數據網格PDF在C#/ Asp.Net
//*************************************************
//
// Author:
// Ryan Van Aken ([email protected])
// (C) 2009 Ryan Van Aken
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//*************************************************
//SQL Connection Settings -----------
public string strConn = ConfigurationManager.ConnectionStrings["BLAH-Here"].ConnectionString;
//-----------------------------------
protected void Page_Load(object sender, EventArgs e)
{
//Grab the same data as the datagrid [report view] on the reporting page
//Then set the "ContentType" to "application/vnd.ms-excel" which will generate the .XSL file
//---Retrieve the Report from SQL, drop into DataSet, then Bind() it to a DataGrid
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
SqlDataAdapter cmd1 = new SqlDataAdapter("EXEC [dbo].[spStatReport] @CompanyID=" + Session["CompanyID"] + ", @StatReportID=" + Request.QueryString["ReportID"].ToString() + ", @StartDate='" + Request.QueryString["StartDate"].Replace("-", "/").ToString() + "', @EndDate='" + Request.QueryString["EndDate"].Replace("-", "/").ToString() + "';", conn);
cmd1.SelectCommand.CommandType = CommandType.Text;
DataSet dsReports = new DataSet("tblReporting");
cmd1.Fill(dsReports);
conn.Close();
DataGrid dtaFinal = new DataGrid();
dtaFinal.DataSource = dsReports.Tables[0];
dtaFinal.DataBind();
dtaFinal.HeaderStyle.ForeColor = System.Drawing.Color.White;
dtaFinal.HeaderStyle.BackColor = System.Drawing.Color.DarkGray;
dtaFinal.ItemStyle.BackColor = System.Drawing.Color.White;
dtaFinal.AlternatingItemStyle.BackColor = System.Drawing.Color.AliceBlue;
//---Create the File---------
Response.Buffer = true;
Response.ClearContent();
Response.ClearHeaders();
//---For PDF uncomment the following lines----------
//Response.ContentType = "application/pdf";
//Response.AddHeader("content-disposition", "attachment;filename=FileName.pdf");
//---For MS Excel uncomment the following lines----------
//Response.ContentType = "application/vnd.ms-excel";
//Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
//---For MS Word uncomment the following lines----------
//Response.ContentType = "application/vnd.word";
//Response.AddHeader("content-disposition", "attachment;filename=FileName.doc");
//---For CSV uncomment the following lines----------
//Response.ContentType = "text/csv";
//Response.AddHeader("content-disposition", "attachment;filename=FileName.csv");
//---For TXT uncomment the following lines----------
//Response.ContentType = "text/plain";
//Response.AddHeader("content-disposition", "attachment;filename=FileName.txt");
EnableViewState = false;
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
//---Renders the DataGrid and then dumps it into the HtmlTextWriter Control
dtaFinal.RenderControl(hw);
//---Utilize the Response Object to write the StringWriter to the page
Response.Write(sw.ToString());
Response.Flush();
Response.Close();
Response.End();
}
0
您可以嘗試this並將內容類型更改爲PDF。
1
您可以嘗試開發使用PDFSharp一個非常簡單的PDF庫.NET
0
這個工作了偉大的接受它並沒有什麼,儘管我把他們的網站上爲我樹立的利潤。有沒有辦法爲此的Word部分做到這一點?我還發現PDF部分不起作用。
(大後期出口)
相關問題
- 1. 轉換HTML頁面PDF
- 2. DataList to PDF導出
- 3. 將HTML頁導出爲PDF
- 4. c#將pdf轉換爲html
- 5. ASP.Net頁面導出爲pdf
- 6. ASP.Net頁面導出爲pdf
- 7. PDF將本地頁面從HTML轉換爲PDF
- 8. Html轉換爲PDF的PDF轉換
- 9. 轉換HTML頁面爲JPG
- 10. XMLWorkerHelper將html頁面轉換爲pdf只生成前2頁
- 11. 將Datalist導出爲每頁受限行的PDF
- 12. 將XML文件轉換爲HTML頁面
- 13. c#從html轉換爲pdf,xls
- 14. 將HTML導出爲PDF(C++,Windows)
- 15. 使用dompdf將頁面轉換爲PDF
- 16. 將JSP頁面轉換爲PDF
- 17. 轉換同一頁面PDF
- 18. 將html文件轉換爲PDF文件?
- 19. 導出爲PDF以外的頁面時出現更多頁面?
- 20. 如何將html頁面的內容轉換爲pdf
- 21. PDF格式轉換爲HTML頁面明智使用PDFBOX庫
- 22. 所有的HTML頁面都不會轉換爲PDF與SelectPdf
- 23. 如何將HTML頁面轉換爲PDF然後下載它?
- 24. 縮小HTML頁面並轉換爲A4尺寸pdf
- 25. 如何使用Javascript,PHP等將html + CSS頁面轉換爲pdf?
- 26. 如何使用ITEXT或PDFCROWD API將HTML頁面轉換爲PDF
- 27. 如何在django中將動態html頁面轉換爲pdf?
- 28. 將html轉換爲pdf時插入的空白頁面
- 29. 如何使用經典ASP VBScript將HTML頁面轉換爲PDF?
- 30. 如何將PDF轉換爲Android中的HTML頁面?
嘿感謝的人,這真是幫了:)神高速 – ferronrsmith 2009-06-24 23:31:33
iTextSharp的是另一種選擇來看待。 – RichardOD 2009-07-13 07:51:37