整合?是蝦咪碗糕?
其實就是你可以用寫code的方式去控制Microsoft Office Word Excel...etc
第一步
要去微軟的官網下載Office主要 Interop 組件 (PIA)
就我所知目前有三個版本
分別是Office XP
oxppia.exe
Office 2003
O2003PIA.EXE
Office 2007
PrimaryInteropAssembly.exe
比較需要注意的是
Office 2003和Office 2007的PIA都需要先安裝Microsoft .Net Framework 1.1
接下來我會用C#+Office 2003 Powerpoint當作例子一步步介紹
1.首先先建立一個視窗應用程式
2.加入參考在COM下找到Microsoft Office 11.0 Object Library(當然要灌完Office 2003 PIA才會出現)
還有Microsoft PowerPoint 11.0 Object Library(因為等一下舉powerpoint作例子其餘word...類推)
參考的地方就會出現Microsoft.Office.Core和PowerPoint如此一來,就能夠使用Office的函式囉
3.接下來要示範的是開一個powerpoint並且將他另存為jpg
宣告library部分先加入
using Microsoft.Office.Core;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
//宣告一個powerpoint的應用程式
PowerPoint.Application pptApp = new PowerPoint.Application();
//宣告prestation程式作為開檔轉存用途
PowerPoint.Presentation pptPre;
//開檔
pptPre = pptApp.Presentations.Open(FileName,
MsoTriState.msoTrue,
MsoTriState.msoFalse,
MsoTriState.msoFalse);
//存成JPG
pptPre.SaveAs(FileName, PowerPoint.PpSaveAsFileType.ppSaveAsJPG, MsoTriState.msoTrue);
//完成
4.另外如果要處理COMException 要記得using System.Runtime.InteropServices;
參考的地方就會出現Microsoft.Office.Core和PowerPoint如此一來,就能夠使用Office的函式囉
3.接下來要示範的是開一個powerpoint並且將他另存為jpg
宣告library部分先加入
using Microsoft.Office.Core;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
//宣告一個powerpoint的應用程式
PowerPoint.Application pptApp = new PowerPoint.Application();
//宣告prestation程式作為開檔轉存用途
PowerPoint.Presentation pptPre;
//開檔
pptPre = pptApp.Presentations.Open(FileName,
MsoTriState.msoTrue,
MsoTriState.msoFalse,
MsoTriState.msoFalse);
//存成JPG
pptPre.SaveAs(FileName, PowerPoint.PpSaveAsFileType.ppSaveAsJPG, MsoTriState.msoTrue);
//完成
4.另外如果要處理COMException 要記得using System.Runtime.InteropServices;

請先 登入 以發表留言。