做影视网站风险大,做网站需要什么内容,国家品牌网,商丘网站制作公司一二三网络推广VSTO 得到Office文档的选中内容#xff08;Word、Excel、PPT、Outlook#xff09; 原文:VSTO 得到Office文档的选中内容#xff08;Word、Excel、PPT、Outlook#xff09; 目的#xff1a;得到在Word、Excel、PPT、Outlook中选中的一段内容。 Word: private string GetSel… VSTO 得到Office文档的选中内容Word、Excel、PPT、Outlook 原文:VSTO 得到Office文档的选中内容Word、Excel、PPT、Outlook 目的得到在Word、Excel、PPT、Outlook中选中的一段内容。 Word: private string GetSelectCont() { string w ; Word.Selection sec appWord.Selection; Word.Words wds sec.Words; w wds.Application.Selection.Text; return w.Trim(); } Outlook: private string GetSelectCont(Outlook.Inspector Inspector) { string w ; Word.Document document Inspector.WordEditor; w document.Application.Selection.Words.Application.Selection.Text; return w.Trim(); } 注无法得到标题等之类的选中内容。 PPT: private string GetSelectCont() { string w ; PowerPoint.Selection sec appPPT.ActiveWindow.Selection; string word sec.TextRange.Text; return word.Trim(); } Excel: private string GetSelectCont() { string w ; object[,] result; object res1; string res2; Excel.Workbook wbook Globals.ThisAddIn.Application.ActiveWorkbook; //当前活动workbook Excel.Worksheet wsheet (Excel.Worksheet)wbook.ActiveSheet; //当前活动sheet Excel.Range range (Excel.Range)wsheet.Application.Selection; //当前选中的cells int count range.Count; res1 (object)range.Value2; //如果选中多个单元格 if (count 1) { int row_count range.Rows.Count; int col_count range.Columns.Count; result (object[,])res1; for (int i 1; i row_count; i) { for (int j 1; j col_count; j) { if (result[i, j] ! null) { w (string)result[i, j] ; } } } } else { //如果选中单个 if (res1 null) { w ; } else { res2 res1.ToString(); w res2; } } return w.Trim(); } 注Excel比较复杂这只能得到选中单个或多个单元格的内容却不能得到某个单元格中mark起来的内容正在查找解决办法。。。 posted on 2015-06-16 10:40 NET未来之路 阅读(...) 评论(...) 编辑 收藏 转载于:https://www.cnblogs.com/lonelyxmas/p/4580136.html