Unplanned
Last Updated: 24 Jan 2025 17:15 by Martin Ivanov
Martin Ivanov
Created on: 24 Jan 2025 17:15
Category: RichTextBox
Type: Bug Report
0
RichTextBox: The exported document cannot be opened in MS Word when contains paragraph indent values (w:firstLine) saved in a scientific notation

When the exported document contains a very precise indent values, these are saved using scientific notation, which is unsupported in MS Word. Opening the file in Word results in the following error: "Word experienced an error trying to open the file."

Image

Here is an example of the troublesome setting in the body of the produced document:

<w:ind w:firstLine="6.420405952667352E-06" w:left="76.53543090820312" w:right="0" />

To work this around, you can open the exported document with the WordsProcessing library. This will give you a RadFlowDocument object which then can be exported to a file again. This will save the indent values properly in the new document.

 var dplProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider();
 using (var inputStream = File.OpenRead("../../../originalFile.docx"))
 {
     Telerik.Windows.Documents.Flow.Model.RadFlowDocument flowDoc = dplProvider.Import(inputStream, TimeSpan.FromSeconds(5));
     using (var outputStream = File.OpenWrite("../../../convertedFile.docx"))
     {
         dplProvider.Export(flowDoc, outputStream, TimeSpan.FromSeconds(5));
     }
 }


Or if you use the RichTextBox document model only to create documents in code (without using the RadRichTextBox control), you can replace the code with the WordsProcessing API.


0 comments