String strPic("D:\\捕获.PNG");
OleVariant WordFile(strPic+_T(".doc"));
WordApp->Connect();
OleVariant NewTemplate(false);
OleVariant Template;
OleVariant DocumentType(0);
OleVariant Visible(false);
//调用Add函数
WordApp->Documents->Add(Template,NewTemplate,DocumentType,Visible);
//连接到新建的文档
WordDocument->ConnectTo(WordApp->Documents->Item(Variant(1)));
BSTR FileName=strPic.w_str();
TImage* imagePdf = new TImage(this);
imagePdf->Picture->LoadFromFile(strPic);
WordApp->Selection->PageSetup->PageHeight =imagePdf->Picture->Height;
WordApp->Selection->PageSetup->PageWidth =imagePdf->Picture->Width;
imagePdf->Picture->Graphic = NULL;
delete imagePdf;
imagePdf=NULL;
OleVariant LinkToFile(false), SaveWithDocument(false);
WordDocument->InlineShapes->AddPicture(FileName);
OleVariant pdfFile(strPic+_T(".pic.pdf"));
OleVariant format(17);
WordDocument->SaveAs(pdfFile, format);
OleVariant changeClose(false);
WordDocument->Close(changeClose);
WordApp->Disconnect();
报错:
this->AddPicture(FileName, LinkToFile, SaveWithDocument, Range, (Word_2k::InlineShape**)&prop))
Error: 800A1420 (-2146823136) @ c:\\program files (x86)\\embarcadero\\rad studio\\7.0\\include\\vcl\\Word_2K.h/32262\nPress [Y]es to terminate,[N]o to continue and [C]ancel to Debug