2014-08-29 165 views
1

我們需要直接以Word或PDF的形式生成RDLC報告,而無需使用報告查看器。這裏我們有兩個問題。將RDLC報告呈現爲word文檔(如docx,而不是doc)

1)使用格式「WORDOPENXML」將報表呈現爲docx時。 MS Word(2013)無法打開生成的文件。它給出了以下錯誤,

很抱歉,我們無法打開docx,因爲我們發現它的內容有問題 文件已損壞,無法打開。

然而,它可以使用格式爲「WORD」作爲文檔生成。然後它可以成功打開。

但我更願意將它作爲Docx生成,如果可能的話。

2)儘管我們可以將其生成爲doc文件,但標題部分中的背景圖像缺失。我們使用信頭作爲報告的背景圖片。

將報告生成爲PDF時沒有問題。

以下是用於生成報告的代碼。

ReportViewer reportViewer = new ReportViewer();   
LocalReport localReport = new LocalReport(); 
localReport.ReportPath = Path.Combine(_env.ReportPath, "RollReport.rdlc"); 

    //Set the datasource for the report 
    localReport.DataSources.Clear(); 
    localReport.DataSources.Add(new ReportDataSource("Details", dtBCDetails)); 
    localReport.DataSources.Add(new ReportDataSource("Properties", dtPropDetails)); 
    localReport.DataSources.Add(new ReportDataSource("Insurence", dtInsurence)); 
    localReport.DataSources.Add(new ReportDataSource("PropertyOwners", dtPropertyOwners)); 

    //Pass parameters to the report 
    localReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { new Microsoft.Reporting.WebForms.ReportParameter("BodyCorporateID", bcid.ToString()) }); 
     localReport.Refresh(); 

    //Get the byte stream for the report rendered as PDF 
    byte[] bytes = localReport.Render(format, null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings); 
    Stream repStream = new MemoryStream(bytes); 

任何幫助將不勝感激。 謝謝 Wijitha

回答

3

不知道,如果你還需要的信息,但我可以用的docx至少可以幫你......如果你使用的不是字作爲格式參數WORDOPENXML,一個的docx文件產生。

相關問題