使用Office Interlop更新Word Table [英] Word Table Update using Office Interlop

查看:237
本文介绍了使用Office Interlop更新Word Table的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在努力完成这项工作,但直到现在我都没有在网络上找到任何答案.这是我的问题,我在Office 2003上创建了一个doc文件,并且其中有一个表(标头和第一个空行).如何从C#中选择该表并在其中添加新行? [我从列表视图填充表格].

请帮我.
问候.

P.S.
这是我的代码:

Hi,

I`m struggling to make this work, but till now i didn''t found any answers on the web. Here is my problem, i have a doc file created on office 2003 and i have a table in it ( header and a first empty row ). How can i select that table from C# and add a new row in it? [ I populate the table from a listview ].

Please help me.
Regards.

P.S.
Here is my code:

Word.ApplicationClass myWordApp = new Word.ApplicationClass(); // our app
            Word.Document myWordDoc = new Word.Document(); // our doc

            object nothing = System.Reflection.Missing.Value; // void value
            object filename = @"D:\LeadTemplate.doc"; // template
            object notTrue = false; // our boolean false;

            myWordApp.Visible = false; 
            myWordDoc = myWordApp.Documents.Add(ref filename, ref nothing, ref nothing, ref nothing);

            // Company Name
            object oBookmark = "CNameBookMark";
            myWordDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = comboBox1.Text.ToString();
            // Invoice Date Generation
            DateTime dtToday = DateTime.Now;
            string dateN = dtToday.ToString("dd/MM/yyyy", CultureInfo.CreateSpecificCulture("en-US"));
            object dBookmark = "CurrentDateBookmark";
            myWordDoc.Bookmarks.get_Item(ref dBookmark).Range.Text = dateN.ToString();

object dest = @"D:\qfspinv"+InvoiceNumber+" Lead Statement "+comboBox1.Text.ToString()+".doc";

            myWordDoc.SaveAs(ref dest, 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);
            myWordApp.Application.Quit(ref notTrue, ref nothing, ref nothing);

推荐答案

以下是从头开始创建表的链接:
http://msdn.microsoft.com/en-us/library/office/aa192483%28v = office.11​​%29.aspx [
如果()看起来在
此处,则可能需要在表上使用括号[]. [^ ] [/编辑]

希望很简单;)
Here is a link to create a table from scrach:
http://msdn.microsoft.com/en-us/library/office/aa192483%28v=office.11%29.aspx[^]

And if you want to find an excisting table you simply write myWordDoc.Tables(1).Cell(1,1).Value ="blablabla" and you have it. Remember that word and excel indexes start at 1 not 0. So that was that :)

You may have to use brackes [] on the tables insted if () look Here[^][/Edit]

Easy, I hope ;)


这篇关于使用Office Interlop更新Word Table的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆