在单词中查找文本并将其替换为表格

时间:2013-09-19 20:40:10

标签: asp.net office-interop com-interop

我使用Asp.Net和Interop.Word.dll来读取word文档。我需要这样的东西。我有关键词。我找到它并用桌子替换它。我用这个过程替换了一个文本。没关系。现在我尝试用表替换字符串。任何人都可以这样做吗? 提前谢谢。

我尝试下面的代码。

   foreach (Microsoft.Office.Interop.Word.Range tmpRange in doc.StoryRanges)
        {

            object replaceAll = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;
            object findme = "##tablo1##";

            //object replaceme = misyonval;
            tmpRange.Application.Selection.Find.ClearFormatting();
            tmpRange.Application.Selection.Find.Text = (string)findme;


            tmpRange.Application.Selection.Find.Replacement.ClearFormatting();

            object start = tmpRange.Start;
            object end = tmpRange.End;


            List<User> users = GetDummyUserData();
            int noOfRows = users.Count + 1;
            int noOfColumns = 5;
           Microsoft.Office.Interop.Word.Table table = doc.Tables.Add(doc.Range(ref start, ref end), noOfRows, noOfColumns, ref nullobj, ref nullobj);

            AddColumnHeaders(ref table);
            for (int i = 1; i <= users.Count; i++)
            {
                table.Rows[i + 1].Cells[1].Range.Text = users[i - 1].FirstName;
                table.Rows[i + 1].Cells[2].Range.Text = users[i - 1].LastName;
                table.Rows[i + 1].Cells[3].Range.Text = users[i - 1].Email;
                table.Rows[i + 1].Cells[4].Range.Text = users[i - 1].Address;
                table.Rows[i + 1].Cells[5].Range.Text = users[i - 1].Pincode.ToString();
            }
            table.set_Style("Colorful List");



        }

0 个答案:

没有答案