执行查找和在C#中的excel文档中替换 [英] Perform find & replace in excel doc in C#

查看:98
本文介绍了执行查找和在C#中的excel文档中替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个用C#动态填充的邮资标签.

I am trying to create a postage label that is populated dynamically in C#.

我想我可以做的就是在Excel中创建标签,这样我可以使布局变得完美,然后使用OpenXML替换字段.即,我有一个名为XXAddressLine1XX之类的字段,我想在其中编辑XML,并用数据库中的实际Address Line 1替换该文本.

What I thought I could do was create the label in Excel so I could get the layout perfect, then use OpenXML to replace the fields. i.e. I have fields called things like XXAddressLine1XX, where I want to edit the XML and replace that text with the actual Address Line 1 from the database.

以前有没有人做过类似的事情并且可以发布一些我可以尝试的代码?我以前使用OpenXML对Word文档进行此操作,但是在c#中使用OpenXML时,似乎无法找到Excel文档的XML数据,因此正努力取得进展.

Has anyone actually done something similar to this before and could post some code up that I could try? I've used OpenXML to do this with word documents before, but I can't seem to find the XML data for the Excel document when using OpenXML in c# so am struggling to make progress.

或者是,或者有什么更好的方法可以尝试做到这一点?

Either that, or are there any better methods I could try to accomplish this?

推荐答案

每时每刻,都有一个编程问题,最好使用非编程解决方案来解决.长期以来,企业一直需要大量打印邮件标签,最近几十年来,诸如Microsoft Word之类的程序通过邮件合并"功能使此操作变得非常简单.请参阅

Every now and then, there's a programming problem that is best solved with a non-programming solution. Businesses have had the need for printing mailing labels en masse for a long time, and in recent decades programs like Microsoft Word make this really simple via the "mail merge" feature. See http://office.microsoft.com/en-us/word-help/demo-use-mail-merge-to-format-and-print-mailing-labels-HA001190394.aspx for an example.

Word的邮件合并将使您可以连接到各种数据源.给定的示例使用Excel电子表格,但您也可以使用Access或SQL数据库等.

Word's mail merge will allow you to connect to a variety of data sources. The given example uses an Excel spreadsheet, but you can also use Access or SQL Databases, etc.

这篇关于执行查找和在C#中的excel文档中替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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