firstly,read from xml file by DOMDocument or SAX, then produce a new class of Word.Application by class Wizard,you can select Add class from type library in Class Wizard, and find the Msword8.olb or Msword9.olb then you can write like that : _Application oWordApp; if (!oWordApp.CreateDispatch("Word.Application", NULL)) { AfxMessageBox("CreateDispatch failed.", MB_OK | MB_SETFOREGROUND); return; }
//Create a new document Documents oDocs; _Document oDoc; oDocs = oWordApp.GetDocuments(); oDoc = oDocs.Add(vOpt, vOpt); //Note for Word 2000: The Add method has 4 arguments in Word 2000. If //you wrapped the classes from the Word type library (msword9.olb), //modify the Add method to provide 4 optional arguments: // oDoc = oDocs.Add(vOpt, vOpt, vOpt, vOpt); //Add text to the document Selection oSel; oSel = oWordApp.GetSelection(); oSel.TypeText("one"); oSel.TypeParagraph(); oSel.TypeText("two"); oSel.TypeParagraph(); oSel.TypeText("three"); //Save the document _Document oActiveDoc; oActiveDoc = oWordApp.GetActiveDocument(); oActiveDoc.SaveAs(COleVariant("c:\\doc1.doc"), COleVariant((short)0), vFalse, COleVariant(""), vTrue, COleVariant(""), vFalse, vFalse, vFalse, vFalse, vFalse); //Quit the application oWordApp.Quit(vOpt, vOpt, vOpt);
TO phiger(phiger) : 你说的这些我都知道. 我是想知道怎么样直接将xml文件转成word文件,如果不行的话怎样读出xml的内容
i don't know how to convert the xml to word document directly,and i think it does not work.if you want read the xml file,you can use DOMDocument object or SAX,you can refer to MSDN or XMLSDK
就是怎样把XML文件里的数据转换成Word文件
then produce a new class of Word.Application by class Wizard,you can select Add class from type library in Class Wizard, and find the Msword8.olb or Msword9.olb
then you can write like that : _Application oWordApp;
if (!oWordApp.CreateDispatch("Word.Application", NULL))
{
AfxMessageBox("CreateDispatch failed.", MB_OK | MB_SETFOREGROUND);
return;
}
//Create a new document
Documents oDocs;
_Document oDoc;
oDocs = oWordApp.GetDocuments();
oDoc = oDocs.Add(vOpt, vOpt);
//Note for Word 2000: The Add method has 4 arguments in Word 2000. If
//you wrapped the classes from the Word type library (msword9.olb),
//modify the Add method to provide 4 optional arguments:
// oDoc = oDocs.Add(vOpt, vOpt, vOpt, vOpt); //Add text to the document
Selection oSel;
oSel = oWordApp.GetSelection();
oSel.TypeText("one");
oSel.TypeParagraph();
oSel.TypeText("two");
oSel.TypeParagraph();
oSel.TypeText("three"); //Save the document
_Document oActiveDoc;
oActiveDoc = oWordApp.GetActiveDocument();
oActiveDoc.SaveAs(COleVariant("c:\\doc1.doc"),
COleVariant((short)0),
vFalse, COleVariant(""), vTrue, COleVariant(""),
vFalse, vFalse, vFalse, vFalse, vFalse); //Quit the application
oWordApp.Quit(vOpt, vOpt, vOpt);
你说的这些我都知道.
我是想知道怎么样直接将xml文件转成word文件,如果不行的话怎样读出xml的内容
我要用到msxml3.0
根据msdn里的说明,我在代码里加入了#pragma comment(lib,"msxml2.lib")
#include "msxml2.h"
可是编译的时候却报错说msxml2.h找不到?
到底msxml2.h在哪?MSDN里面说:
Requirements
Implementation: msxml3.dll, msxml2.lib
Header and IDL files: msxml2.h, sxml2.idl
怎样遍历一个XML中的所有节点及其元素