国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

記錄Office Add-in開發經驗

2019-11-17 02:52:38
字體:
來源:轉載
供稿:網友

記錄Office Add-in開發經驗

Posted on 2014-09-21 11:21 協思 閱讀(...) 評論(...) 編輯 收藏

原創文章轉載請注明出處:@協思, http://zeeman.VEVb.com

得益于微軟系強大的共通能力和Visual Studio的開發支持,做Office插件不是什么難事。一點經驗記錄如下:

1. 如果要同時開發WordOutlook插件,那么可將復用的代碼封閉到獨立的Library中。

2. 在可安裝.NET Framework 4的系統上,可以嵌入WPF組件

3. 由于Office的安全模型,安裝部署里需要可信任證書的簽名。

4. 初始化代碼可在ThisAddIn添加,如Startup、Shutdown、application.NewMailEx...

代碼集錦


1. 獲取文件名:

app = Globals.ThisAddIn.Application;Path.GetExtension(app.ActiveDocument.FullName)

2.檢查文檔是否保存:

app = Globals.ThisAddIn.Application;if (!app.ActiveDocument.Saved){    if (MessageBox.Show("This command publish the disk version of a file to the server. Do you want to save your changes to disk before 

3. 獲取文檔內容,并添加自己的信息

public byte[] GetDocumentContent(Word.Document wordDoc, string headerText, string footerText){    //使用Mail.RTFBody獲取文檔內容會丟失部分格式,所以這里還是采用剪貼板方式。    //復制文檔內容到剪貼板    wordDoc.Content.Copy();    using (RichTextBox rtb = new RichTextBox())    {        //添加頭部信息        rtb.AppendText(headerText);        rtb.SelectAll();        rtb.SelectionFont = new Font("Courier New", 11);        rtb.SelectionColor = Color.Green;        //添加正文        rtb.Select(rtb.TextLength, 0);        rtb.Paste();        Clipboard.Clear();        //添加尾部信息        rtb.SelectionFont = new Font("Courier New", 11);        rtb.SelectionColor = Color.Green;        rtb.AppendText(footerText);        using (System.IO.MemoryStream stream = new MemoryStream())        {            rtb.SaveFile(stream, RichTextBoxStreamType.RichText);            return stream.ToArray();        }    }}

4. outlook郵件正文轉換為word文檔:

object selObject = currentExplorer.Selection[1];MailItem mail = selObject as MailItem;if (mail == null){    MessageBox.Show("non-mail item not supported.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);    return;}Word.Document wordDoc = (Word.Document)mail.GetInspector.WordEditor;

資源下載


Office Control Identifiers: http://www.microsoft.com/en-us/download/details.aspx?id=6627

Office Document Extractor: http://code.msdn.microsoft.com/office/CSOfficeDocumentFileExtract-e5afce86


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 黔江区| 丽水市| 景德镇市| 黑山县| 兴城市| 宁陵县| 怀化市| 西林县| 洪江市| 铜川市| 龙口市| 敦煌市| 沂南县| 江达县| 怀宁县| 福泉市| 谢通门县| 上犹县| 阳曲县| 会宁县| 成安县| 楚雄市| 连江县| 行唐县| 无锡市| 渝中区| 镇安县| 江城| 高邑县| 乌兰浩特市| 静宁县| 即墨市| 伊宁县| 崇阳县| 屏边| 鄂托克旗| 郴州市| 内乡县| 济宁市| 新化县| 内丘县|