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:
-
Open exported reports in a wide range of applications: Users can open and modify the exported Word document in any of the following applications.
- Customize reports after exporting: Positioning and arrangement of report elements in the exported document is implemented using the OOXML format (.Docx) which provides a natural document flow for editing the exported documents.
- Use Word automation features: With support for automation features in the OOXML format (.Docx), tasks that previously required manual adjustments in the exported Word document are now handled automatically. Report elements such as page header and footer, expressions, heading levels, and table of contents are automatically transformed to the OOXML format (.Docx).
- Set compatibility mode: You can render a report as a Word document that is compatible with Microsoft Word 2007-2010 as well as Microsoft Word 2013 using the DocumentCompatibleVersion property.
The following steps provide an example of rendering a report in the Word format (.doc or .docx).
- Create a new Visual Studio project.
- In the New Project dialog that appears, select ActiveReports 12 Page Report Application and specify a name for the project in the Name field.
- Click OK to create a new ActiveReports 12 Page Report Application. By default a Page report is added to the project.
- Add reference to GrapeCity.ActiveReports.Export.Word.v12.dll assembly in the project.
- On the Form.cs or Form.vb that opens, double-click the title bar to create the Form_Load event.
- 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
- Although background colors for controls export to Word documents, background colors for sections such as Body and Page Header or Footer do not.
- The BackgroundImage is not supported when used in TextBox and CheckBox controls embedded in data regions such as Table and Tablix.
- The BackgroundImage is not supported for reports, and for List, Container, Shape, FormattedText, Table, and Tablix report controls.
- KeepTogether property of Table/Tablix is not supported.
- LineStyle for Line control set as Double appears Solid.
- BorderStyle for Shape and Container controls set as Double appears Solid.
- Some FormattedText tags, for example <b>bi</b> and <s>es</s>, are not exported to Word.
- Image alignments other than the defaults (HorizontalAlignment: Left and VerticalAlignment: Top) are not supported.
- EMF text in the Image report item is blurred when exported to Word.
- Checkbox color does not affect the color of the square.
OOXML format
Report properties
- The LineSpacing property of a report's style sheet, StartPageNumber property of the report, PrintOnLastPage property of the PageHeader and PageFooter are not supported.
- For Page reports, some of the NumberingStyle property (DocumentMap settings) options are not supported. The supported NumberingStyle options are Decimal, DecimalZero, LowerLetter, UpperLetter, LowerRoman, UpperRoman.
- Background image is not supported for report item except Shape.
- The BackgroundRepeat property of the BackgroundImage is not supported in Page (Page reports) and Body (RDL reports).
- For RDL reports, Background and Border properties of Page Header or Page Footer are not supported.
- Microsoft Word calculates the columns width by the document width. A RDL report calculates the columns width based on the body width, therefore the width of columns in an exported RDL report may differ from an original RDL report.
- In Microsoft Word, the maximum supported page size is 22 inches (55.87 cm) wide and 22 inches (55.87 cm) high. If an exported report exceeds the maximum size, some data may be lost during export.
- In Microsoft Word, a table can have a maximum of 63 columns. If an exported report table has more than 63 columns, then the table is split and therefore an exported document may differ from an original report.
- A repeated Table Footer (the RepeatOnNewPage property of Table Footer) or multiple repeated headers on a single page are not supported.
- The OverflowPlaceHolder control is not supported.
- If the PrintOnFirstPage property of PageHeader or PageFooter is set to False, then both PageHeader and PageFooter will not be available on the first page of the exported document.
- The report data gets rendered only in first theme if a Page report containing multiple themes is exported to Docx format.
Report controls
- The Inset, Outset, and Windowsinset border styles (in BorderStyle property) are not supported.
- The Map, Chart, Image, Barcode, SparkLine, Bullet, and CustomControl report controls are exported as an image. If a report control uses the BorderColor, BorderStyle or BorderWidth properties, a report is exported as a table.
- The BorderWidth property of report controls is not exported as is and may differ from the original BorderWidth value.
- PageBreaks are not fully supported. The report contents exported to the Word's table or cell items do not support the page breaks.
- For Shape report control, if the BorderStyle property is set to Double, it is exported as Solid.
- For Line control, if LineStyle property is set to Double/Transparent, it is exported as Solid
- For BandedList data region, only the BandedList Header is repeated on each page. The BandedList Footer, GroupHeaders and GroupFooters are not supported.
- Tablix data region is exported as a single table without horizontal split.
- For Image control, Border properties and Padding properties are not supported if the Sizing property is set to Clip.
- For Container report control, rounding corners (the RoundingRadius property) are not supported.
- RepeatToFill property for Table and Tablix is not supported.
- Multipage Calendar is not supported.
- Images embedded in a Table data region are not properly supported.
- Pagination is not supported due to difference in the layouts of ActiveReports and Word.
- Page Number in Section (Page N of M(Section)) is not supported.
- KeepTogether property of Table/Tablix is not supported.
- Horizontal aligned images may overlap in iWord.
- The properties set to the 'Body' region of a Subreport are not exported.
FormattedText
- FormattedText is exported as it is. It does not support all HTML and CSS features.
- The <a> tag without a href attribute, <abbr> and <q> tags are exported as simple text.
- For Border Styles - Inset and Outset, the <ul> tags are not exported.
- The BackgroundColor, BackgroundImage, BorderColor, BorderStyle and BorderWidth properties are not supported.
- Anchors with an href attribute are exported as hyperlinks.
- Headers like h1, h2, etc. are exported as corresponding Microsoft Word built-in header styles.
TableOfContents
- The TextAlign, DisplayPageNumber, TextIndent, and Overline TextDecoration properties are not supported.
- The Source property of the Document Map settings is not fully supported. Only the Headings Only option of the Source property is supported.
- If a report uses more than one TableOfContents controls, the properties of the first TableOfContents are applied to the other TableOfContents controls in the exported document.
- The FillCharacter property is exported as dots.
- The background of TOC control appears black on opening exported file in Apache OpenOffice.
TextBox/CheckBox
- If the Format property is set to Numeric or Date, the exported TextBox has a right alignment. Other Format values are exported with the left alignment.
- The Transparent color for text is exported as white.
- The Underline for numbered lists, Right-To-Left (RTL) option of the Direction, Angle, ShrinkToFit and Overline TextDecoration properties are not supported.
- The action Jump to report is not supported.
- The tb-rl (vertical text) option of the WritingMode property is not supported. TextBoxes with the WritingMode property set to tb-rl are exported as lr-tb.
- The NoWrap option of the WrapMode property is exported as WordWrap.
- The LineSpacing property of an exported document will differ from the original report. This is because in Microsoft Word, the line spacing is calculated by the font size value of a report control plus the line spacing value of a report control.
- For CheckBox control, the CheckAlignment property is exported as MiddleRight for TopRight, MiddleRight, and BottomRight options. Other CheckAlignment options are exported as MiddleLeft.
- Paddings exceeding 31 inches is exported as border spaces.
- Right-To-Left text direction does not work in the Apache OpenOffice.
- On exporting to Word 2013, when the background (shading) and padding are applied on a paragraph, the padding is also applied to the background, so a gap between the border and the background appears on the left side of the paragraph.
- CharWrap property is not supported.
- The fields in a TextBox control are evaluated as follows:
- PageNumber and TotalPages expressions are exported as special fields, evaluated by a text editor (Word or other).
- The fields placed in Header or Footer are automatically evaluated.
- The fields placed in the Body should be re-evaluated manually by clicking 'Update field' from context menu.
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
- Hyperlinks - Hyperlinks on TextBox and Image controls are rendered as hyperlinks in the Microsoft Word.
- Bookmarks - Bookmarks in the report are rendered as Microsoft Word bookmarks. Bookmark links are rendered as hyperlinks that link to the bookmark labels within the document.
- TOC AutoUpdate - TableofContents control in the report is rendered as Microsoft Word table of contents.
See Also