diff --git a/PROMS/DataLoader/Documents.cs b/PROMS/DataLoader/Documents.cs index f853adc6..092ce8aa 100644 --- a/PROMS/DataLoader/Documents.cs +++ b/PROMS/DataLoader/Documents.cs @@ -71,6 +71,7 @@ namespace DataLoader WordDoc myWordDoc = null; try { + LoadAndSaveRichTextBox(tmpName); myWordDoc = new WordDoc(tmpName); /* 16-bit's type[1] used the following codes to represent the respective lpi setting * @@ -148,18 +149,7 @@ namespace DataLoader CloseMSWord(myWordDoc); frmMain.AddError("Attempting to fix the file and try again."); // Get the rtf from the file - string rtf = LoadFileRaw(tmpName); - // Parse for margins because the RTB will remove them - Match match = Regex.Match(rtf, @"((\\marg[^\\]+)+)", RegexOptions.Singleline); - using (RichTextBox rtb = new RichTextBox()) - { - rtb.Rtf = rtf; // Allow the RichTextBox to parse the RTF - rtf = rtb.Rtf; // Get the RTF back from the RichTextBox - } - // Add the margins to the RTB output - rtf = rtf.Replace(@"\ansi", @"\ansi" + match.Value); - // Save the modified rtf to the temporary file - SaveFile(rtf, tmpName); + LoadAndSaveRichTextBox(tmpName); attempt = 2; break; default: @@ -191,7 +181,31 @@ namespace DataLoader frmMain.AddError("Missing rtf file: {0}", fname); return docid; } - + private RichTextBox _MyRichTextBox = null; + public RichTextBox MyRichTextBox + { + get + { + if (_MyRichTextBox == null) + _MyRichTextBox = new RichTextBox(); + return _MyRichTextBox; + } + } + private void LoadAndSaveRichTextBox(string tmpName) + { + string rtf = LoadFileRaw(tmpName); + // Parse for margins because the RTB will remove them + Match match = Regex.Match(rtf, @"((\\marg[^\\]+)+)", RegexOptions.Singleline); + rtf = rtf.Replace("\\sectd", ""); + rtf = rtf.Replace("\\sbkpage", ""); + rtf = rtf.Replace("\\sect", "\\page"); + MyRichTextBox.Rtf = rtf; // Allow the RichTextBox to parse the RTF + rtf = MyRichTextBox.Rtf; // Get the RTF back from the RichTextBox + // Add the margins to the RTB output + rtf = rtf.Replace(@"\ansi", @"\ansi" + match.Value); + // Save the modified rtf to the temporary file + SaveFile(rtf, tmpName); + } private static void TryToShowMSWord(WordDoc myWordDoc) { try