09-14-2021 08:56 AM
I am trying to open a .doc file in LabWindows/CVI, then save this file as an .rtf file without using macros. I need to do this since I need to open the file as an ASCII file using LabWindows/CVI and search for various key phrases in the file.
I am using Windows 10 operating system and LabWindows/CVI Version 8.0.1.
I have Word 9.0 Object Library (word2000.fp) and WordReport (wordreport.fp) instruments loaded
Here is my coding (this section works fine):
RESULT = WordRpt_ApplicationNew (VTRUE, &WORD_APP_HANDLE); // Opens new Microsoft Word application
RESULT = WordRpt_DocumentOpen (WORD_APP_HANDLE, TEST_FILE, &WORD_FILE_HANDLE); // Opens file in variable "TEST_FILE" which is a .docx file using the Microsoft Word application
when I execute the next line, the line saves the file as C:\TEMP\New_Test_File.rtf, but the file is still in .doc format (when opened with Notepad, it is still a binary file). I need it to be an ASCII file, which can be searched easily.
RESULT = WordRpt_DocumentSaveAs (WORD_FILE_HANDLE, "C:\\TEMP\\New_Test_File.rtf"); // Save word file as .rtf file
09-16-2021 02:40 PM
If you just need to find text within the file, how about if you try saving it as HTML instead? You can use the function WordRpt_DocumentSaveAsHTML.
09-22-2021 12:35 PM
There is one problem with converting to an .rtf file. If the text has formatting or is part of a text table, you have to write a routine to strip off the formatting code as shown below:
.txt file
Pressure (mb)
990.1
.rtf file
{\rtlch\fcs1 \af1 \ltrch\fcs0 \fs20\cf1\loch\af1\hich\af1\dbch\af1\insrsid16721103 \hich\af1\dbch\af1\loch\f1 Pressure (mb)}{\rtlch\fcs1 \af1 \ltrch\fcs0
\fs20\cf1\loch\af1\hich\af1\dbch\af1\insrsid10499488 \nestcell{\nonesttables
\par }}{\rtlch\fcs1 \af1 \ltrch\fcs0 \fs20\cf1\loch\af1\hich\af1\dbch\af1\insrsid16721103 \hich\af1\dbch\af1\loch\f1 990.1}