Home > Software engineering >  MFC read word file content, including content appropriate, such as font, font size, etc.?
MFC read word file content, including content appropriate, such as font, font size, etc.?

Time:10-31

Specific issues, as shown in the title
I want to read the word document includes the specific format, but did not find a good method to feasible, which master taught a thing or two

CodePudding user response:

Laura file format

CodePudding user response:

reference 1st floor Sime507 response:
research Laura file format

CodePudding user response:

Microsoft did not release the standard format for office?

CodePudding user response:

The
reference 3 floor kk_Kevin response:
was not published Microsoft office standard format?


Not published ms office file formats

CodePudding user response:

Note: 2007 in the office, some change the name of the class to 0, after such as CRange0 CDocument0, some function name also changed, change format changes such as getText to get_Text (),



Read the word document:

Remember to modify CDocuments, CDocument0 etc in the header file is as follows://remember other plus # pragma once

# pragma once

# import "K: \ \ Program Files \ \ Microsoft Office \ \ Office XXX XX \ \ MSWORD OLB" no_namespace raw_interfaces_only \
Rename (" FindText _FindText ", ""),
Rename (" Rectangle ", "_Rectangle") \
Rename (" ExitWindows _ExitWindows ", "")

As I said, after the import typelib, add Application Document.. Such as, the following is a snippet

# include "CApplication. H"
# include "CDocument0. H"
# include "CDocuments. H"

CApplication oWord;
CDocuments oDocs;
CDocument0 oDoc;

Void CVCreadwriteRTFDlg: : OnBnClickedButton1 ()
{
//variable declaration
COleVariant vTrue (TRUE) (short),
VFalse ((short) FALSE),
VOpt ((long) DISP_E_PARAMNOTFOUND VT_ERROR);

CApplication oWordApp;
CSelection oSel;
CDocuments oDocs;
CDocument0 oDoc;
CParagraphs paragraphs;

CStringArray aryText;

Long paCounst;
Int lc;

//first establish a word instance objects
if (! OWordApp. CreateDispatch (TEXT (" Word. Application "))) {

AfxMessageBox (TEXT (" CreateDispatch failed. "), MB_OK & amp; BrvbarMB_SETFOREGROUND);
return;//must be returned, otherwise the program crashes
}

//show the object file, you can not call this sentence, don't show the object file
OWordApp. Set_Visible (TRUE);

//create a document
ODocs=oWordApp. Get_Documents ();

//open a new document, to e: \ \ BuildJobEdit RTF file content added to the new document
CComVariant TPL (_T (" e: \ \ BuildJobEdit RTF ")), NewTemplate (false), a DocType (0), Visble;
ODoc=oDocs. Add (& amp; The TPL, & amp; NewTemplate, & amp; DocType, & amp; Visble);

//all of the selected document content
OSel=oWordApp. Get_Selection ();
OSel. WholeStory ();//this sentence must have, otherwise the subsequent code is invalid,

//get all the section
Paragraphs=oSel. Get_Paragraphs ();

PaCounst=paragraphs. Get_Count ();

//will all of each paragraph in the array
For (lc=1; Lc & lt; PaCounst + 1; Lc++) {

//get a
CParagraph com.lowagie.text.paragraph;
Com.lowagie.text.paragraph=paragraphs. The Item (lc) (long);

//get a text
CRange range=com.lowagie.text.paragraph. Get_Range ();
Cstrings strRangeText=range. Get_Text ();

CFont font=range. Get_Font ();

//set the size and color of text
//font. Put_Color (RGB (0255, 0));
//font. Put_Size (12);
//AfxMessageBox (strRangeText);

//save the array
AryText. Add (strRangeText);

//release object
Com.lowagie.text.paragraph. ReleaseDispatch ();

}

CodePudding user response:

Word provides a set of COM interfaces can programmatically access the document content