qt集成dsoframer.ocx打開office辦公軟件


最近一段時間真是事情太多了,前不久項目中一個嵌入office軟件的問題,由於沒有時間研究,且項目的需求是瀏覽word文檔,偷了一個懶,把word文檔轉換成pdf文檔,然后嵌入libcef瀏覽器給打開了

   現在回過頭來,重新研究了這方面的直接辦法,在網上查了多方面的資料,終於決定要使用ocx這個方案來完成此項功能,可限於資源問題,ocx方面的資料 沒怎么接觸過,所以就盲目的在晚上看別人的東西,不過皇天不負有心人,最終還是讓我成功的搞定了這個問題,然后覺着,這個ocx也不過如此么,總的來說說 還是比較簡單

    我當前機器環境:windwos7 64位  dsoframer 1.3 qt5.5.1 vs2013

下邊我說下我自己的步驟:

1、下載dsoframer.ocx,然后使用命令注冊regsvr32.exe dsoframer.ocx 

2、運行regedit.exe 在HKEY_LOCAL_MACHINE目錄下搜索dsoframer,獲取CLSID的值,這個是用作ocx的唯一標示,如果沒有搜索到,可以下載其他的dsoframer,重新注冊,或者給我留言

3、接下來直接上代碼

 1 QAxWidget * _Word = new QAxWidget(this);
 2 
 3 _Word->setControl("{00460182-9E5E-11d5-B7C8-B8269041DD57}");
 4 
 5 _Word->setProperty("Visible", true);
 6 
 7 QString filePath = QFileDialog::getOpenFileName(0, "Open doc file", QString(), "*.doc");
 8 
 9 if (filePath.isEmpty())
10 
11 return;
12 
13 _Word->dynamicCall("Open(string)", filePath);
14 
15 _Word->dynamicCall("SetCaption(string)", "ocx test");
16 
17 _Word->dynamicCall("SetMenuAccelerators(bool)", false);
18 
19 _Word->dynamicCall("SetMenubar(bool)", false);
20 
21 QGridLayout * ply = new QGridLayout(this);
22 
23 ply->addWidget(_Word, 0, 0, 1, 1);
24 
25 ply->setContentsMargins(0, 0, 0, 0);
26 
27 ui.widget->setLayout(ply);
View Code

效果圖如下:

dsoframer.ocx打開office軟件

dsoframer的相關接口,不過常用的也就那么幾個

BeforeDocumentClosed(IDispatch*,bool&) Document,Cancel

BeforeDocumentSaved(IDispatch*,QString,bool&) Document,Location,Cancel

OnActivationChange(bool) fGoingActive

OnDocumentClosed()

OnDocumentOpened(QString,IDispatch*) File,Document

OnFileCommand(dsoFileCommandType,bool&) Item,Cancel

OnPrintPreviewExit()

OnSaveCompleted(IDispatch*,QString,QString) Document,DocName,FullFileLocation

exception(int,QString,QString,QString) code,source,disc,help

propertyChanged(QString) name

signal(QString,int,void*) name,argc,argv

Activate()

Close()

CreateNew(QString) ProgIdOrTemplate

EnableFileCommand(dsoFileCommandType) Item bool

ExecOleCommand(int) OLECMDID

ExecOleCommand(int,QVariant) OLECMDID,Options

ExecOleCommand(int,QVariant,QVariant&) OLECMDID,Options,vInParam

ExecOleCommand(int,QVariant,QVariant&,QVariant&)  OLECMDID,Options,vInParam,vInOutParam

GetDataObjectContent(QVariant) ClipFormatNameOrNumber QVariant

Open(QVariant) Document

Open(QVariant,QVariant) Document,ReadOnly

Open(QVariant,QVariant,QVariant)    Document,ReadOnly,ProgId

Open(QVariant,QVariant,QVariant,QVariant)Document,ReadOnly,ProgId,WebUsername

Open(QVariant,QVariant,QVariant,QVariant,QVariant) Document,ReadOnly,ProgId,WebUsername,WebPassword    

PrintOut()

PrintOut(QVariant) PromptUser 

PrintOut(QVariant,QVariant) PromptUser,PrinterName

PrintOut(QVariant,QVariant,QVariant) PromptUser,PrinterName,Copies

PrintOut(QVariant,QVariant,QVariant,QVariant)

PromptUser,PrinterName,Copies,FromPage

PrintOut(QVariant,QVariant,QVariant,QVariant,QVariant) PromptUser,PrinterName,Copies,FromPage,ToPage

PrintOut(QVariant,QVariant,QVariant,QVariant,QVariant,QVariant)  PromptUser,PrinterName,Copies,FromPage,ToPage,OutputFile

PrintPreview()

PrintPreviewExit()

Save()

Save(QVariant) SaveAsDocument

Save(QVariant,QVariant) SaveAsDocument,OverwriteExisting

Save(QVariant,QVariant,QVariant)

SaveAsDocument,OverwriteExisting,WebUsername

Save(QVariant,QVariant,QVariant,QVariant) SaveAsDocument,OverwriteExisting,WebUsername,WebPassword

SetActivationPolicy(dsoActivationPolicy) ActivationPolicy

SetBackColor(QColor) BackColor

SetBorderColor(QColor) BorderColor

SetBorderStyle(dsoBorderStyle) BorderStyle

SetCaption(QString) Caption

SetDataObjectContent(QVariant,QVariant) ClipFormatNameOrNumber,DataByteArray

SetEnableFileCommand(dsoFileCommandType,bool) Item,rhs

SetEventsEnabled(bool) EventsEnabled

SetForeColor(QColor) ForeColor

SetFrameHookPolicy(dsoFrameHookPolicy) FrameHookPolicy

SetHostName(QString)HostName

SetLockServer(bool) LockServer

SetMenuAccelerators(bool) MenuAccelerators

SetMenubar(bool) Menubar SetModalState(bool) ModalState

SetTitlebar(bool) Titlebar

SetTitlebarColor(QColor) TitlebarColor

SetTitlebarTextColor(QColor) TitlebarTextColor

SetToolbars(bool) Toolbars

ShowDialog(dsoShowDialogType) DlgType

_PrintOutOld()

_PrintOutOld(QVariant) PromptToSelectPrinter

如果想看哪種方法調用失敗或者是異常,請參考C++ gui程序附加dos輸出窗口

注:需要完整事例的可以給我留言

 

如果您覺得文章不錯,不妨給個 打賞,寫作不易,感謝各位的支持。您的支持是我最大的動力,謝謝!!! 

 

  


很重要--轉載聲明

  1. 本站文章無特別說明,皆為原創,版權所有,轉載時請用鏈接的方式,給出原文出處。同時寫上原作者:朝十晚八 or Twowords
  2. 如要轉載,請原文轉載,如在轉載時修改本文,請事先告知,謝絕在轉載時通過修改本文達到有利於轉載者的目的。 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM