我從我的應用程序中插入一些數據在Word文檔中,並再次保存。我現在的代碼對於放在word文檔中的表格中的文本可以正常工作,但它不會獲取不在表格中的文本。例如,單詞文檔的第1頁不在表格中,代碼跳過第1頁並立即轉到第2頁,其中有一個文本放在表格中,並且它正在替換文本。 這裏是我的代碼:從c中的word文檔取代正常的文本#
Document docc = app.Documents.Open(ref path, ref o, ref readOnly, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o);
docc.Activate();
try
{
foreach (Paragraph p in docc.Paragraphs)
{
Range rng = p.Range;
Style sty = (Style)p.get_Style();
if ((bool)rng.get_Information(WdInformation.wdWithInTable) == true)
{
foreach (Cell c in rng.Cells)
{
if (rng.Cells.Count > 0)
{
string testtt = c.Range.Text.ToString();
if (c.Range.Text.ToString().Contains("[Company_Name]\r\a"))
// c.Next.Range.Text = "Sacramento";
c.Range.Text = "Sacramento";
}
}
docc.Save();
}
docc.Close(ref o, ref o, ref o);
}
}
我知道這行:
if ((bool)rng.get_Information(WdInformation.wdWithInTable) == true)
獲取與只表的頁面,但我想知道這樣我可以從網頁中獲取數據沒有表格並修改那裏的文字。
謝謝,這就是我所需要的。祝你有美好的一天 – Laziale