ActiveReports 12
Rendering to Word
ActiveReports 12 > ActiveReports User Guide > Concepts > Exporting > Rendering Extensions > Rendering to Word

The WordRenderingExtension class renders your reports to the native Microsoft Word file formats. You can export Page reports and RDL reports to the Office Open XML (OOXML) format (.Docx) or Word HTML format (.Doc) using the FileFormat property.

The Word HTML format (.Doc) provides greater layout accuracy for Page and RDL Reports in Microsoft Word, on the other hand, OOXML format (.Docx) provides excellent editing experience for the exported reports.

The OOXML format (.Docx) is recommended in the following scenarios:

The following steps provide an example of rendering a report in the Word format (.doc or .docx).

  1. Create a new Visual Studio project.
  2. In the New Project dialog that appears, select ActiveReports 12 Page Report Application and specify a name for the project in the Name field.
  3. Click OK to create a new ActiveReports 12 Page Report Application. By default a Page report is added to the project.
  4. Add reference to GrapeCity.ActiveReports.Export.Word.v12.dll assembly in the project.
  5. On the Form.cs or Form.vb that opens, double-click the title bar to create the Form_Load event.
  6. Add the following code inside the Form_Load event to render your report in .OOXML or .HTML file format.
Note: To export your report in Word HTML format (.Doc), change the FileFormat property option from OOXML to HTML format as depicted below. 
wordSetting.FileFormat = GrapeCity.ActiveReports.Export.Word.Page.FileFormat.HTML

To export a report in .Docx file format

Visual Basic.NET code. Paste INSIDE the Form Load event.
Copy Code
' 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# code. Paste INSIDE the Form Load event.
Copy Code
// 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);           

Word Rendering Extension Properties

ActiveReports offers several options to control how reports render to Microsoft Word.

Common properties (HTML and OOXML)

Property Description
Author Sets the name of the author that appears in the Author field of the Properties dialog in the rendered Word document.
FileFormat Sets the output file format to HTML (.Doc) or OOXML (.Docx). By default the file format is set to HTML format.
Title Sets the title for a document that appears in the Title field of properties dialog in the rendered Word document.

HTML format

Property Description
BaseUrl Sets the base URL for any relative hyperlinks that appear in the Hyperlink base field of the Properties dialog in the rendered Word document.
Generator Sets the identity of the document generator in the rendered Word document.
PageHeight Sets the height of the report pages in inches for the rendered Word document. The value in this property overrides the original settings in the report.
PageWidth Sets the width of the report pages in inches for the rendered Word document. The value in this property overrides the original settings in the report.
UseMhtOutput Indicates whether Mht output is to be used for the resultant Word document or not.

OOXML format

Property Description
CompanyName Sets the name of the organization or company that appears in the Company field of Properties dialog in the rendered Word document.
DocumentCompatibilityVersion

Sets the compatibility mode of the document to the latest version (Microsoft Word 2013) or to previous versions (Microsoft Word 2007 - 2010) of Word. By default the compatibility version is set to Word2007. 

DpiX Sets the horizontal resolution of the images in the rendered Word document. By default DpiX is set to 96.
DpiY Sets the vertical resolution of the images in the rendered Word document. By default DpiY is set to 96.
PageOrientation Sets a value that specifies whether the document pages should be printed in portrait or landscape in the rendered Word document.
PaperSize Sets the paper size for the page.
Password Sets a password that must be provided to open the rendered Word document.
ReadOnlyRecommended Sets a value that indicates whether Microsoft Office Word displays a message whenever a user opens the document, suggesting that the document is read-only.
WritePassword Sets the write password that is required for saving changes in the rendered Word document.
TOCAutoUpdate Automatically updates the TableOfContents control while opening the Word document. By default TOCAutoUpdate is set to False. 

Limitations

HTML format

OOXML format

Report properties

Report controls

Interactivity

HTML format

Reports rendered in a Word format supports both Bookmarks and Hyperlinks. However, if visibility toggling (like in a drill-down report) is essential to your report, it is recommended to use the HTML rendering extension. If a Document map is essential to your report, it is recommended to use the PDF rendering extension.

OOXML format

See Also