架构师_程序员_码农网

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

搜索
查看: 21263|回复: 1

[资料] Microsoft.Office.Interop.Word文档动态生成表格

[复制链接]
发表于 2016-1-28 23:41:44 | 显示全部楼层 |阅读模式
QQ截图20160128233706.jpg

效果图如上:

代码如下:

  1. public void test(string bookname)
  2.         {
  3.             //在书签处插入文字
  4.             //object oStart = bookname;//word中的书签名
  5.             //Range range = doc.Bookmarks.get_Item(ref oStart).Range;//表格插入位置
  6.             //range.Text = "这里是您要输入的内容";//在书签处插入文字内容

  7.             //在书签处插入表格
  8.             object oStart = bookname;//word中的书签名
  9.             Range range = doc.Bookmarks.get_Item(ref oStart).Range;//表格插入位置      
  10.             Microsoft.Office.Interop.Word.Table tab_Pat = doc.Tables.Add(range, 2, 4, ref missing, ref missing);//开辟一个2行4列的表格
  11.             tab_Pat.Range.Font.Size = 10.5F;
  12.             tab_Pat.Range.Font.Bold = 0;

  13.             tab_Pat.Columns[1].Width = 50;
  14.             tab_Pat.Columns[2].Width = 65;
  15.             tab_Pat.Columns[3].Width = 40;
  16.             tab_Pat.Columns[4].Width = 40;

  17.             tab_Pat.Cell(1, 1).Range.Text = "病历号";
  18.             tab_Pat.Cell(1, 2).Range.Text = "PatientNO";
  19.             tab_Pat.Cell(1, 3).Range.Text = "身高";
  20.             tab_Pat.Cell(1, 4).Range.Text = "Height";

  21.             tab_Pat.Cell(2, 1).Range.Text = "姓名";
  22.             tab_Pat.Cell(2, 2).Range.Text = "PatientName";
  23.             tab_Pat.Cell(2, 3).Range.Text = "体重";
  24.             tab_Pat.Cell(2, 4).Range.Text = "Weight";

  25.         }
复制代码


参考资料:  http://www.cnblogs.com/eye-like/p/4121219.html

如果想要表格居中显示:

  1. doc.Tables[1].Select();//选中表格
  2.             app.Selection.Tables[1].Rows.Alignment = WdRowAlignment.wdAlignRowCenter;//表格居中
复制代码


以上两句,没有测试,参考资料:http://www.cnblogs.com/lei2007/archive/2012/07/16/2594065.html




上一篇:卧槽,base64字符串转图片终于搞定了
下一篇:提示:413 Request Entity Too Large 的解决方法
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
发表于 2016-1-29 14:52:57 | 显示全部楼层
  1. tab_Pat.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleThickThinLargeGap;
  2.             //  tab_Pat.Borders.InsideLineStyle = WdLineStyle.wdLineStyleSingle;
复制代码


这个是表格边框,没有试
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

免责声明:
码农网所发布的一切软件、编程资料或者文章仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。

Mail To:help@itsvse.com

QQ|小黑屋|架构师 ( 鲁ICP备14021824号-2 )|网站地图

GMT+8, 2026-1-31 05:39

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表