我想将网格视图数据导出为pdf而不使用iTextSharp我可以创建的方式。 我无法像excel那样创建文件?
DataSet dsReport = new DataSet();
dsReport = (DataSet)ViewState["report"];
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment;filename=Detail.pdf");
Response.ContentType = "application/pdf";
StringWriter sw = new StringWriter();
HtmlTextWriter htm = new HtmlTextWriter(sw);
Repeater repgetres = this.rptrabc;
repgetres .DataSource = dsReport;
repgetres .DataBind();
repgetres .RenderControl(htm);
Response.Write(sw.ToString());
Response.End();
答案 0 :(得分:1)
未经过测试,但Microsoft.Office.Interop.Word.Application将提供帮助
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
object missingvalue = System.Reflection.Missing.Value;
object dummyfilename = "D://DummyFile.docx";
string pdfdata = "D://HtmlFileData.html";
string pdffilename= "D://PDFFile.pdf";
object savechanges = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;
object ofalse = false;
Microsoft.Office.Interop.Word.Document doc = word.Documents.Open(ref dummyfilename, ref missingvalue, ref missingvalue, ref missingvalue, ref missingvalue, ref missingvalue, ref missingvalue, ref missingvalue, ref missingvalue, ref missingvalue, ref missingvalue, ref missingvalue, ref missingvalue, ref missingvalue, ref missingvalue, ref missingvalue);
doc.Words.Last.InsertFile(pdfdata, ref missingvalue, ref ofalse, ref missingvalue, ref missingvalue);
doc.ExportAsFixedFormat(pdffilename, Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF, false, Microsoft.Office.Interop.Word.WdExportOptimizeFor.wdExportOptimizeForOnScreen, Microsoft.Office.Interop.Word.WdExportRange.wdExportAllDocument, 1, 1, Microsoft.Office.Interop.Word.WdExportItem.wdExportDocumentWithMarkup, true, true, Microsoft.Office.Interop.Word.WdExportCreateBookmarks.wdExportCreateNoBookmarks, true, true, false, ref missingvalue);
doc.Close(ref savechanges,ref missingvalue,ref missingvalue);
word.Quit(ref savechanges, ref missingvalue, ref missingvalue);