PROBLEM:
Exporting to Word or Rich Text from Crystal Reports (CR) results in a document with formatting that makes it difficult to edit and use as a Word document. (If you have a CR version after CR XI, please let us know if they have improved their Word export.) In most versions of Crystal Reports there are two kinds of Word/RTF exports, and each has its own problem:
Export with Frames
This option may display as "Microsoft Word (RTF)" or "Word (Exact) Format" depending on your version of CR. Each report text box or field is displayed in a separate Word Frame. These frames are very annoying if you want to edit the Word document, because they're very easy to accidentally move around, and if you shorten or lengthen the text, they do not automatically change size or wrap to the next page.
Export without Frames
This option may display as "Microsoft Word - Editable (RTF)" or "Word for Windows document" depending on your version of CR. At least with the CR versions we've tested, this export inserts paragraph marks at the end of each line even within text-wrapping memo fields. They need to be removed if the text is to wrap properly when edits are made. These paragraph marks are impossible to distinguish from the paragraph marks we want to keep, i.e. those between fields/text boxes and line breaks that actually occur in our data. In some versions of CR, the export also loses HTML interpretation and lines, borders, and other "graphic" objects.
SOLUTION:
One option is to export to pdf instead of Word, or export to Word without frames and don't worry about ragged ends of lines within paragraphs. But if you need a clean, editable Word document, you'll need to apply special formatting in your report and use Word macros to convert the document. You can also use this method for applying Word styles to your document, which allows you to add a Table of Contents.
- In Crystal Reports, apply special formatting that you will use for search and replace in Word. (Your report will not be suitable for exporting to pdf when it is optimized for exporting to Word, unless you use a parameter to conditionally format your report for Word or pdf export.) Specifically:
- Do NOT html-interpret your fields, i.e., let the html codes show (the default in CR).
- Create a way to distinguish real line breaks from text-wrapping breaks. E.g., begin each real paragraph with a bold heading (so you can search for bold) or a special symbol such as <br>. (<br> is ideal because <br> and <br /> will need to be converted to carriage returns in Word anyway.)
- If you wish to use Word styles in your document (for creating a table of contents or applying formatting that doesn't export well from CR), create a way to distinguish the text you want to add each style to. My preferred method for distinguishing text is to use fake (or real) html tags, e.g. put <H1> before and </H1> after your field so that it looks like <H1>{my_field}</H1>. Another option is to apply a certain color or font size to the text.
- Export your document to Word without Frames ("Microsoft Word - Editable (RTF)" or "Word for Windows document").
- In Word, create and run a macro that searches for the special formatting you set up in step 1 and replaces it with paragraph marks or styles. It's tricky, but you only have to do it once for your report, and run it each time you do an export.Here is what the macro should do:
- Carriage returns: Search for ^p (paragraph mark) and replace with nothing. (Yes, this removes all paragraph marks from your document, which will look odd, but it's only temporary.) Search for the formatting or symbol (e.g. <br>) you used in the report to indicate where you want carriage returns (step 1b), and replace with ^p (paragraph mark).
- Search for the formatting or symbol you used in the report to indicate where you want Word Styles (step 1c) and replace with that style. < and > are wildcard characters in Word so instead of searching for "<H1>*</H1>" you need to search for "\<H1\>*\</H1\>"
- Replace the html codes with real formatting and special html characters. See NS Word macros for use with Biotics for a macro that already exists to do this.
It's usually an iterative process to get this to work: after you run the Word macros you will likely find something that didn't work right and that you have to make edits to the CR report and reexport to fix it.
If you need help with this process or want to see sample reports or macros, contact Kristin Snow.