我想创建一个按钮选项,它将整个数据列表转换为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. ASP.Net页面导出为pdf
- 3. ASP.Net页面导出为pdf
- 4. 将html网页转换为pdf页面(用户将下载的pdf文件)
- 5. Html转换为PDF的PDF转换
- 6. 转换HTML页面为JPG
- 7. XMLWorkerHelper将html页面转换为pdf只生成前2页
- 8. c#从html转换为pdf,xls
- 9. 将HTML导出为PDF(C++,Windows)
- 10. 使用dompdf将页面转换为PDF
- 11. 转换同一页面PDF
- 12. 导出为PDF以外的页面时出现更多页面?
- 13. 将html文件转换为PDF文件?
- 14. 如何将HTML页面转换为PDF然后下载它?
- 15. 如何使用ITEXT或PDFCROWD API将HTML页面转换为PDF
- 16. PDF格式转换为HTML页面明智使用PDFBOX库
- 17. 如何使用经典ASP VBScript将HTML页面转换为PDF?
- 18. 如何使用Javascript,PHP等将html + CSS页面转换为pdf?
- 19. 如何将PDF转换为Android中的HTML页面?
- 20. 所有的HTML页面都不会转换为PDF与SelectPdf
- 21. 如何将html页面的动态内容转换为pdf
- 22. ASP.NET MVC将包含表单的HTML页面转换为PDF
- 23. Html转换为PDF与webkit转换
- 24. 将PDF转换为HTML
- 25. ASP.NET将HTML转换为PDF
- 26. 将PDF转换为HTML
- 27. Rails:将HTML转换为PDF?
- 28. 导出html格式为pdf
- 29. 将HTML转换为PDF文件
- 30. PHP:将html文件转换为pdf
嘿感谢的人,这真是帮了:)神高速 – ferronrsmith 2009-06-24 23:31:33
iTextSharp的是另一种选择来看待。 – RichardOD 2009-07-13 07:51:37