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

首頁 > 開發 > 綜合 > 正文

用C#在PowerPoint文檔中搜索文本

2024-07-21 02:26:47
字體:
來源:轉載
供稿:網友

用編程的方式根據對象模型很容易實現在word、excel文檔中搜索文本,在powerpoint里面也同樣如此,使用對象模型有助于我們了解office的文檔結構。

  搜索的思路和方法基本是一樣的,用powerpoint應用程序對象打開指定的文檔,用文檔對象獲取文檔,再使用合適的對象將文檔分割成搜索范圍適中的對象進行搜索。

  打開powerpoint的vba幫助文檔vbapp10.chm,根據對象模型圖,很容易找到我們需要的幾個集合和對象:application、presentations、presentation、slides、slide、textframe、textrange。其中presentation代表一個 powerpoint 文檔,slide表示powerpoint文檔中的單張幻燈片,textframe是幻燈片上的文本框,textrange是文本框中的文本。

  打開powerpoint文檔:
  

  string filename="";

  
  powerpoint.application pa=new powerpoint.applicationclass();

  powerpoint.presentation pp=pa.presentations.open(filename,

   microsoft.office.core.msotristate.msotrue,

   microsoft.office.core.msotristate.msofalse,

   microsoft.office.core.msotristate.msofalse);

    open()方法的第三個參數在幫助文檔中的說明如下:

  untitled 可選。msotristate 類型。指定文件是否有標題。

  

 

  因為是untitled,所以按照上面的代碼,打開文檔之后才能引用powerpoint文檔的標題,如果不想使用標題,就要把枚舉msofalse改成msotrue。

  搜索文本:

  string[] strkeywordlist={}; //要搜索的文本

  powerpoint.textrange otext;

  foreach(powerpoint.slide slide in pp.slides)

  {

   foreach(powerpoint.shape shape in slide.shapes)

   {

   foreach(string strkeyword in strkeywordlist)

   {

   otext=null;

   otext=shape.textframe.textrange.find(strkeyword,0,microsoft.office.core.msotristate.msofalse,microsoft.office.core.msotristate.msotrue);

   if (otext!=null)

   {

   messagebox.show("文檔中包含指定的關鍵字 "+strkeyword+" !","搜索結果",messageboxbuttons.ok);

   continue;

   }

   }

   }

  }

 

 



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 长顺县| 深州市| 大渡口区| 稻城县| 永清县| 石景山区| 砀山县| 通河县| 荃湾区| 古田县| 靖边县| 高平市| 望江县| 塔城市| 孟村| 新乡县| 兴安县| 万州区| 轮台县| 离岛区| 上林县| 句容市| 巨鹿县| 洛扎县| 凤阳县| 昂仁县| 福建省| 兴海县| 威海市| 桑日县| 隆化县| 仙居县| 德化县| 襄汾县| 沙雅县| 皋兰县| 武鸣县| 武清区| 封开县| 栾城县| 偏关县|