2009-06-16 100 views
0

我在c#中編寫了一段代碼以在microsft word文檔中生成報告。範圍:將格式應用於範圍中的子部分

  • 我有一個wid 2列的表。
  • 我通過

    oMainTable.Cell選擇第2列(currentRowNumber,2).Range

  • 每次我必須寫在該細胞我使用上面的代碼與文字的組合的東西財產,InsertParagraph(),InsertAfter()等等等等

現在讓我們說我有這樣的內容:

部分樣本內容部分樣本 內容部分樣本內容部分樣本內容 部分樣本內容 部分樣本內容部分樣本 內容。

New Paragraph Some sample content Some sample content Some sample 

內容的一些樣本內容的一些 樣本內容的一些樣本內容 一些樣本內容

Some Title1 

New Paragraph Some sample content Some sample content Some sample 

內容的一些樣本內容的一些 樣本內容的一些樣本內容 一些樣本內容

New Paragraph Some sample content Some sample content Some sample 

內容部分樣本內容部分 樣品內容有些樣品含量 一些樣本內容

Some Title1 

我想強調和粗斜體適用於someTitle1和someTitle2使得它們並不適用於整個範圍內;並僅限於這兩條文本。

任何幫助?

感謝

+0

我忙着它..請參閱下面的答案。 – 2009-06-18 15:02:23

回答

0

讓我先發一個聲明;-)「**這裏提出的解決方案是我的命中和試驗方法的結果,並撞頭**」

object srchText="Text to be searched and formatted differently from the rest of the range"; 
    oTable.Cell(countRow, 2).Range.Select(); 
    var selectUpdateComment=oTable.Cell(countRow, 2).Range.Application.Selection; 
    selectUpdateComment.Find.Execute2007(ref srchText, ref missing, ref missing, 
ref missing, ref missing, ref missing, ref missing, ref missing, 
ref missing, ref missing, ref missing, ref missing, ref missing, 
ref missing, ref missing, ref missing, ref missing, ref missing,ref missing, ref missing); 

    if(selectUpdateComment.Find.Found) { 
     selectUpdateComment.Font.Bold=1; 
     selectUpdateComment.Font.Underline=WdUnderline.wdUnderlineSingle; 
    } 

我在做這個一個循環,所以每次我必須做Range.Select,否則我wouldnt得到正確的選擇。

請建議更好的方法..