Page tree
Skip to end of metadata
Go to start of metadata

WordRenderingExtension类将您的报告呈现为本机Microsoft Word文件格式。您可以使用FileFormat属性将Page报表和RDL报表导出为Microsoft Office Open XML(OOXML)格式(.Docx)或Word HTML格式(.Doc)。

Word HTML格式(.Doc)为Microsoft Word中的Page和RDL报告提供了更高的布局准确性,另一方面,OOXML格式(.Docx)为导出的报告提供了出色的编辑体验。

在以下情况下,建议使用OOXML格式(.Docx):

在各种应用程序中打开导出的报告:用户可以在以下任何应用程序中打开和修改导出的Word文档。
Microsoft Office 2007年-2013年
Microsoft Office for Mac 2008-2011年
适用于OS X的iWord和Pages v4或更高版本
图书馆
适用于Android的Google Quickoffice
SavySoda的iOS版免费文档(移动办公套件)

注意:除了上面列出的应用程序之外,通过ActiveReports WordRenderingExtension类导出的.Docx文件可能在支持.Docx格式的其他应用程序中工作。

导出后自定义报告:使用OOXML格式(.Docx)在导出的文档中实现报表元素的位置和排列,该格式提供了自然的文档流来编辑导出的文档。

使用Word自动化功能:支持OOXML格式(.Docx)的自动化功能,以前需要在导出的Word文档中进行手动调整的任务现在可以自动处理。报表元素(例如页面页眉和页脚,表达式,标题级别和目录)将自动转换为OOXML格式(.Docx)。

设置兼容模式:可以使用DocumentCompatibleVersion属性将报表呈现为与Microsoft Word 2007-2010和Microsoft Word 2013兼容的Word文档。

以下步骤提供了以Word格式(.doc或.docx)呈现报告的示例。

1、创建一个新的Visual Studio项目。

2、在出现的“新建项目”对话框中,选择“ ActiveReports 14页面报表应用程序”,然后在“名称”字段中指定项目的名称。

3、单击“确定”创建一个新的ActiveReports 14页面报表应用程序。默认情况下,页面报告将添加到项目中。

4、在项目中添加对GrapeCity.ActiveReports.Export.Word包的引用。

5、在打开的Form.cs或Form.vb上,双击标题栏以创建Form_Load事件。

6、在Form_Load事件内添加以下代码,以.OOXML或.HTML文件格式呈现报告。

注意:要以Word HTML格式(.Doc)导出报告,如下所示,将FileFormat属性选项从OOXML更改为HTML格式。
wordSetting.FileFormat = GrapeCity.ActiveReports.Export.Word.Page.FileFormat.HTML
以.Docx文件格式导出报告

Visual Basic.NET代码。粘贴到Form Load事件中。


' Provide the page report you want to render.
Dim report As New GrapeCity.ActiveReports.PageReport()
Dim reportDocument As New GrapeCity.ActiveReports.Document.PageDocument(report)

' Create an output directory.
Dim outputDirectory As New System.IO.DirectoryInfo("C:\MyWord")
outputDirectory.Create()

' Provide settings for your rendering output.
Dim wordSetting As New GrapeCity.ActiveReports.Export.Word.Page.Settings()

' Set the FileFormat property to .OOXML.
wordSetting.FileFormat = GrapeCity.ActiveReports.Export.Word.Page.FileFormat.OOXML

' Set the rendering extension and render the report.
Dim wordRenderingExtension As New GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension()
Dim outputProvider As New GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name))

' Overwrite output file if it already exists.
outputProvider.OverwriteOutputFile = True

reportDocument.Render(wordRenderingExtension, outputProvider, wordSetting)


C#代码。 粘贴到Form Load事件中。


// Provide the page report you want to render.
GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport();
GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(report);

// Create an output directory.
System.IO.DirectoryInfo outputDirectory = new System.IO.DirectoryInfo(@"C:\MyWord");
outputDirectory.Create();

// Provide settings for your rendering output.
GrapeCity.ActiveReports.Export.Word.Page.Settings wordSetting = new GrapeCity.ActiveReports.Export.Word.Page.Settings();

// Set the FileFormat property to .OOXML.
wordSetting.FileFormat = GrapeCity.ActiveReports.Export.Word.Page.FileFormat.OOXML;

// Set the rendering extension and render the report.
GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension wordRenderingExtension = new GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension();
GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name));

// Overwrite output file if it already exists.
outputProvider.OverwriteOutputFile = true;

reportDocument.Render(wordRenderingExtension, outputProvider, wordSetting);





相关资源:


注意

如需寻求在线帮助,请访问 ActiveReports 求助中心

如需了解更多ActiveReports产品特性,请访问 ActiveReports 官方网站

ActiveReports 官方技术交流群:109783140

下载产品体验产品功能:http://www.gcpowertools.com.cn/products/download.aspx?pid=16

  • No labels