word文档转成网页形式!

#include "stdafx.h" #import "D:/Program Files/Microsoft Office/OFFICE11/MSWORD.OLB" named_guids raw_interfaces_only rename("ExitWindows", "wordExitWindows") void wordtohtml() { printf("Automate word to save xxx.doc as onega.htm, test by masterz with VC.NET2003 on Windowx2003, Office2003/n"); Word::_ApplicationPtr app; app.CreateInstance("Word.Application"); Word::DocumentsPtr docs; app->get_Documents(&docs); Word::_DocumentPtr doc; _variant_t vFileName("c://a.doc"); _variant_t vOptional((long)DISP_E_PARAMNOTFOUND,VT_ERROR); _variant_t vTrue(VARIANT_TRUE); _variant_t vFalse(VARIANT_FALSE); docs->Open ( /*[in]*/&vFileName, /*[in] VARIANT * ConfirmConversions*/&vOptional, /*[in] VARIANT * ReadOnly*/&vOptional, /*[in] VARIANT * AddToRecentFiles*/&vOptional, /*[in] VARIANT * PasswordDocument*/&vOptional, /*[in] VARIANT * PasswordTemplate*/&vOptional, /*[in] VARIANT * Revert*/&vOptional, /*[in] VARIANT * WritePasswordDocument*/&vOptional, /*[in] VARIANT * WritePasswordTemplate*/&vOptional, /*[in] VARIANT * Format*/&vOptional, /*[in] VARIANT * Encoding*/&vOptional, /*[in] VARIANT * Visible*/&vOptional, /*[in] VARIANT * OpenAndRepair*/&vOptional, /*[in] VARIANT * DocumentDirection*/&vOptional, /*[in] VARIANT * NoEncodingDialog*/&vOptional, /*[in] VARIANT * XMLTransform*/&vOptional , /*[out,retval]*/ &doc ); _variant_t vCopies((short)1); DeleteFile("c://onega.htm"); _variant_t filename("c://onega.htm"); _variant_t FileFormat((long)Word::wdFormatHTML); doc->SaveAs (&filename,&FileFormat); doc->put_Saved(VARIANT_TRUE); app->Quit(&vOptional,&vOptional,&vOptional); } int main(int argc, char* argv[]) { CoInitialize(NULL); wordtohtml(); CoUninitialize(); return 0; }

你可能感兴趣的:(word文档转成网页形式!)