2017-03-08 77 views
-1

我想將網格視圖數據導出爲pdf,而無需使用iTextSharp如何創建。 我不能創建像excel文件?如何在不使用iTextSharp的情況下使用asp.net c#創建pdf

  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(); 
+1

你可以參考這個, https://forums.asp.net/t/1899940.aspx?下載+ PDF +沒有+ GridView控件使用+ iTextSharp的+ –

回答

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); 
相關問題