winfrom 通過dsoframer實現讀取excel文件報錯

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. 
---> 
System.Runtime.InteropServices.COMException (0x80041103): 
The associated COM server does not support ActiveX Document embedding.

at DSOFramer._FramerControl.Open(Object Document, Object ReadOnly, Object ProgId, Object WebUsername, Object WebPassword)

--- End of inner exception stack trace ---

解決方法:

Open時把第三個progID加上就可以,

打開文檔:

HRESULT Open([in] VARIANT Document, [in, optional] VARIANT ReadOnly, 
[in, optional] VARIANT ProgId, [in, optional] VARIANT WebUsername, [in, optional] VARIANT WebPassword)
打開文檔,可以是本地文件或者是服務器文件

參數:
Document 文檔路徑
ReadOnly 是否已只讀模式打開
ProgId OLE類型
WebUsername 用戶名(訪問網絡的文件時候,有可能需要)
WebPassword 密碼
例子:

axFramerControl1.Open(sPath, true, "Excel.Sheet", "", "");//
DsoFramer1.Open "C:\TestBook.xls"
DsoFramer1.Open "C:\Plain.txt", , "Word.Document"  //用Word來打開c:\plain.txt文件
DsoFramer1.Open "https://secureserver/test/mytest.asp?id=123", True, "Excel.Sheet", "MyUserAccount", "MyPassword"

保存文檔:

HRESULT Save([in, optional] VARIANT SaveAsDocument, [in, optional] VARIANT OverwriteExisting, 
                [in, optional] VARIANT WebUsername, [in, optional] VARIANT WebPassword);
保存文件在本地
DsoFramer1.Save "c:\1.doc"
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容