社区
C#
帖子详情
WinForm里Word模板操作
aizxu
2010-06-15 08:35:26
Word模板里有个表格,想把从数据库取出的多条数据按位置插入到表格中,代码应该怎么写?
...全文
176
2
打赏
收藏
WinForm里Word模板操作
Word模板里有个表格,想把从数据库取出的多条数据按位置插入到表格中,代码应该怎么写?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
2 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
wuyq11
2010-06-15
打赏
举报
回复
using Word = Microsoft.Office.Interop.Word;
Microsoft.Office.Interop.Word._Document Doc = app.Documents.Open(ref sFile, ref optional, ref docreadonly, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref visible, ref optional, ref optional, ref optional, ref optional);
使用书签或自添加table
if (Doc.Bookmarks.Exists("a"))
{
object WdLine = Word.WdUnits.wdLine;
object oEndOfDoc = "a";
Word.Range oRng = Doc.Bookmarks.get_Item(ref oEndOfDoc).Range;
Word.Table tb = Doc.Tables.Add(oRng, 1, 2, ref nothing, ref nothing);
tb.Rows.Alignment = Word.WdRowAlignment.wdAlignRowCenter;
tb.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
tb.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
int i = 1;
tb.Cell(1, 1).Range.Text = "";
tb.Cell(1, 2).Range.Text = "";
}
xiaoxiaoman20
2010-06-15
打赏
举报
回复
中科院IT工程硕士 为IT人加油超经典全套java ee教程免费下载!6月PHP就业班开班在即先实习后上岗,入职年薪5-10万 世界杯竞猜setTimeout与setInterval在不同浏览器下的差异发布Java写的俄罗斯方块源码 算法简单(300行) 注释详细C#编码猜谜,送可用分 Google 提供的广告谷歌关键字广告免费试用高达1000元免费广告费等你拿,1分钟注册,马上获得优惠券!
AdWords.google.com
Winform
可视化打印
模板
设计(完整版)
Winform
可视化打印
模板
设计(完整版)
使用NPOI
操作
制作
word
使用NPOI动态链接库,
操作
生成
word
,包括生成段落。添加文字,添加页眉。插入图片,插入柱形图,表格等
word
模板
替换标签 生成
word
pdf 文件
C#中由
word
模板
替换标签后,同时生成
word
文档,并且生成 pdf文件
.net 按照
word
模板
替换制定内容 含图片 保留格式不变
.net 按照
word
模板
替换制定内容,含图片,保留格式不变,附件是代码 可以直接使用,测试通过,如果不能运行 可以安装Office组件
C#向
word
文档动态插入数据并打印预览
首先机子上安装有office,在COM中添加引用Microsoft.
Word
.11.0.Object.Library(或11.0以上) Microsoft.Office.Interop.
Word
.Application my
Word
App = null; Microsoft.Office.Interop.
Word
.Document doc = null; object Filename = path + "\\" + TaskID + ".docx";//目的文件 object templateFile = System.Windows.Forms.Application.StartupPath + @"\Template.docx";//
模板
文件,有一个五列一行的表 System.IO.File.Copy(templateFile.ToString(), Filename.ToString(), true);//
模板
WORD
中有一个五列的表头,分别是卡号,串口号,发送指令条数,接收指令条数,收发成功率 my
Word
App = new Microsoft.Office.Interop.
Word
.Application(); doc = my
Word
App.Documents.Open(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); /////显示页码 object oAlignment = Microsoft.Office.Interop.
Word
.WdPageNumberAlignment.wdAlignPageNumberCenter; object oFirstPage = true; oAlignment = Microsoft.Office.Interop.
Word
.WdPageNumberAlignment.wdAlignPageNumberCenter; my
Word
App.Selection.Sections[1].Footers[Microsoft.Office.Interop.
Word
.WdHeaderFooterIndex.wdHeaderFooterPrimary].PageNumbers.Add(ref oAlignment, ref oFirstPage); my
Word
App.Selection.Sections[1].Footers[Microsoft.Office.Interop.
Word
.WdHeaderFooterIndex.wdHeaderFooterPrimary].PageNumbers.NumberStyle = Microsoft.Office.Interop.
Word
.WdPageNumberStyle.wdPageNumberStyleNumberInDash; for (int i = 2; i < 102; i++)//举例100台 { doc.Tables[1].Rows.Add(ref Nothing);//表格增加一行 doc.Tables[1].Cell(i, 1).Range.Text = "250297";//卡号 doc.Tables[1].Cell(i, 2).Range.Text = "COM12";//串口号 doc.Tables[1].Cell(i, 3).Range.Text = "100";//发送指令条数 doc.Tables[1].Cell(i, 4).Range.Text = "99";//接收指令条数 doc.Tables[1].Cell(i, 5).Range.Text = "99%";//收发成功率 } doc.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); object savechanges = Microsoft.Office.Interop.
Word
.WdSaveOptions.wdDoNotSaveChanges;//不保存挂起的更改 ////下面是直接打印,文档不显示 //doc.PrintOut(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, ref Nothing, ref Nothing, ref Nothing); object readOnly=false; object isVisable = true;////文档打开状态为可视 doc = my
Word
App.Documents.Open(ref Filename, ref Nothing, ref readOnly, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref isVisable, ref Nothing, ref Nothing, ref Nothing, ref Nothing); doc.PrintPreview();//打印预览
C#
110,577
社区成员
642,558
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章