导出代码如下:
public void ProcessRequest(HttpContext context)
{
String filePath = context.Request.FilePath;
filePath = filePath.Remove(filePath.Length - 4);
String reportPath = context.Server.MapPath(filePath);
String str =context.Request.QueryString["param"];
PageReport rpt = new PageReport(new FileInfo(reportPath));
String mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
String filename = "test.docx";
context.Response.ContentType = mimeType;
context.Response.Clear();
context.Response.AddHeader("content-disposition", "attachment;filename=" + filename);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
GrapeCity.ActiveReports.Export.Word.Page.Settings wordSetting = new GrapeCity.ActiveReports.Export.Word.Page.Settings();
wordSetting.UseMhtOutput = true;
//docx
wordSetting.FileFormat = GrapeCity.ActiveReports.Export.Word.Page.FileFormat.OOXML;
//doc
//wordSetting.FileFormat = GrapeCity.ActiveReports.Export.Word.Page.FileFormat.HTML;
GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension wordRenderingExtension =
new GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension();
GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();
rpt.Report.ReportParameters[0].DefaultValue.Values.Add("EUNBDD180300029");
rpt.Document.Render(wordRenderingExtension, outputProvider, wordSetting);
outputProvider.GetPrimaryStream().OpenStream().CopyTo(ms);
context.Response.BinaryWrite(ms.ToArray());
context.Response.End();
}
wordSetting.FileFormat = GrapeCity.ActiveReports.Export.Word.Page.FileFormat.OOXML; 这句是导出docx格式的,导出后office2007无法打开,office2010打开格式错乱。
wordSetting.FileFormat = GrapeCity.ActiveReports.Export.Word.Page.FileFormat.HTML; 设置成doc格式后打开是正常的。
附件是doc和docx的文件。
|