我是靠谱客的博主 复杂眼神,这篇文章主要介绍VS操作Word模板中的表格,现在分享给大家,希望可以做个参考。

1、利用Word文档模板创建Word文档

    object filedot = "....//Member.dot";
    Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
    Microsoft.Office.Interop.Word.Document WordDoc = WordApp.Documents.Add(ref filedot, ref Nothing, ref Nothing, ref Nothing);
    WordApp.Visible = true;

2、获取表格,填充内容
    Microsoft.Office.Interop.Word.Selection selection=WordApp.Selection; 
    Microsoft.Office.Interop.Word.Tables newTables = WordDoc.Tables;
    Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables[1];//得到表1

3、移动光标
    object count = 1;
    object WdLine = Microsoft.Office.Interop.Word.WdUnits.wdLine;

    WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//左、右、上移类似

4、在表格中插入行
    WordApp.Selection.InsertRowsBelow(ref count);

5、在表格中填充内容

     newTable.Cell(row, col).Range.Text="";

6、获取表格中的内容

     string s = newTable.Cell(row, col).Range.Text;

7、文件保存
     object filename = "....//保存.doc";  //文件保存路径和文件名
     WordDoc.SaveAs(ref filename, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);

最后

以上就是复杂眼神最近收集整理的关于VS操作Word模板中的表格的全部内容,更多相关VS操作Word模板中内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(109)

评论列表共有 0 条评论

立即
投稿
返回
顶部