首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

将word变换为图片(请妖哥贴代码)

2012-10-14 
将word转换为图片(请妖哥贴代码)妖哥,把你的代码分享一下,谢谢![解决办法]OLE专业户来也!!! 楼主等久了吧.

将word转换为图片(请妖哥贴代码)
妖哥,把你的代码分享一下,谢谢!

[解决办法]
OLE专业户来也!!! 楼主等久了吧. 直接上代码:

C/C++ code
#include <stdio.h>// ---------------------------------------BOOL __stdcall CrnWmfToBmp(LPCSTR lpWmfFile, LPCSTR lpBmpFile){    BOOL bResult = FALSE;    if (!FileExists(lpWmfFile)) return bResult;    TMetafile *pMetafile = new TMetafile;    Graphics::TBitmap *pBitmap = new Graphics::TBitmap;    pBitmap->PixelFormat = pf24bit;    try    {        pMetafile->LoadFromFile(lpWmfFile);        pBitmap->Height = pMetafile->Height;        pBitmap->Width = pMetafile->Width;        pBitmap->Canvas->Draw(0, 0, pMetafile);        pBitmap->SaveToFile(lpBmpFile);        bResult = TRUE;    }    __finally    {        delete pBitmap;        delete pMetafile;    }    return bResult;}//---------------------------------------BOOL __fastcall CrnSaveDocPageToSingleBitmap(LPCSTR lpDocFile, int nPage, LPCSTR lpBmpFile){    if (!FileExists(lpDocFile)) return FALSE;    Variant vWordApp;    try    {        vWordApp = Variant::CreateObject("Word.Application");    }    catch(...)    {        MessageBox(NULL, "启动Word出错!",                Application->Title.c_str(), MB_OK | MB_ICONERROR);        return FALSE;    }    vWordApp.OlePropertySet("Visible", false);    vWordApp.OlePropertySet("DisplayAlerts", false);    Variant vDoc = vWordApp.OlePropertyGet("Documents").            OleFunction("Open", WideString(lpDocFile));    vDoc.OleProcedure("Repaginate");    Variant vSelect, vParam, vNewDoc;    vNewDoc = vWordApp.OlePropertyGet("Documents").OleFunction("Add");    vDoc.OleProcedure("Activate");    vSelect = vWordApp.OlePropertyGet("Selection");    vSelect.OleFunction("GoTo", 1, 2, 1, nPage);    vSelect.OleFunction("EndKey", 6, 1);    vSelect.OleProcedure("Copy");    vNewDoc.OleProcedure("Activate");    // 63 63 72 75 6E 2E 63 6F 6D    vWordApp.OlePropertyGet("Selection").OleProcedure("PasteSpecial",        vParam.NoParam(),        false,        0,        false,        9,        vParam.NoParam(),        vParam.NoParam()        );    vNewDoc.OlePropertyGet("InlineShapes").OleFunction("Item", 1).OleProcedure("Select");    vWordApp.OlePropertyGet("Selection").OleProcedure("Copy");    ::OpenClipboard(0);    HANDLE hEmf = ::GetClipboardData(CF_ENHMETAFILE);    if (hEmf)    {        char szEmfFile[MAX_PATH];        strcpy(szEmfFile, ChangeFileExt(lpBmpFile, ".emf").c_str());        HENHMETAFILE h = CopyEnhMetaFile(hEmf, szEmfFile);        if (h > 0)        {            ::DeleteEnhMetaFile(h);            CrnWmfToBmp(szEmfFile, lpBmpFile);            ::DeleteFile(szEmfFile);        }    }    ::CloseClipboard();    vWordApp.OlePropertyGet("Selection").OleProcedure("Delete");    vWordApp.OleProcedure("Quit", 0);    return TRUE;}void __fastcall TForm1::Button1Click(TObject *Sender){    Button1->Enabled = false;    String strPath = ExtractFilePath(ParamStr(0));    // 将123.doc文件的第2页保存为位图    CrnSaveDocPageToSingleBitmap("D:\\ccrun\\123.doc", 2, "D:\\ccrun\\123.bmp");    Button1->Enabled = true;} 

热点排行