0

我使用 Asp.Net 和 Interop.Word.dll 来阅读 word 文档。我需要这样的东西。我在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");



        }
4

0 回答 0