复制/映射excel扩展表之间的数据,Vb.net [英] Copying/Mapping data between excel spread sheets, Vb.net

查看:129
本文介绍了复制/映射excel扩展表之间的数据,Vb.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果可能,我需要使用Vb.net将数据从一个excel spreadworbook复制到另一个,并将数据放入现有excel电子表格中的正确列中。电子表格的列标题匹配,我有几个模板我需要将数据放入,并且列的顺序在每个模板中是不同的,所以我需要一种在模板中搜索列标题,然后将数据复制到那个列。

I need to copy data using Vb.net if possible from one excel spreadworbook to another and place the data into the correct columns in the existing excel spreadsheet. The column titles of the spreadsheets match up, I have several templates I need to place data into and the order of the columns is different in each template so I need a way of searching for a column header in the template and then copying the data into that column.

使用ADO实现这一目标的最佳方法?

Would the best way of achieving this using ADO?

例如,从这个列Test1,Test2和数据的工作簿1

For example move the data from this Workbook1 with columns "Test1", "Test2" and data

Test1   Test2
1         2
12        23
123       234

进入工作簿2,它将具有相同的列名,但可以在不同的顺序:

Into workbook 2 which will have the same column names but could be in a different order:

Test0   Test1   Test1.1  Test2

我需要自动执行此操作,因为我有大量数据要复制和30-40个工作簿模板来复制数据,模板列的顺序不同,不能移动周围。

I need to do this automatically as I have alot of data to copy and 30-40 workbook templates to copy the data into, the templates columns are in different orders and can not be moved around.

推荐答案

有不同的方法可以使用.NET与Excel进行接口。如果您只是想用一个版本的Excel,那么 VSTO 可能是您最简单的解决方案,否则使用其他方法。我喜欢使用 EXCEL-DNA

There are different ways to interface with Excel using .NET. If you are just looking to do it with one version of Excel, then VSTO might be your easiest solution, otherwise use something else. I like to use EXCEL-DNA.

您也可以使用ADO来获取数据,但将其放在另一个中,我认为您需要上面列出的方法之一(因为您需要引用excel对象)。如果您正在使用Excel 2007及以上版本,您还可以直接访问XML文件并以这种方式进行操作(当然,请减去xlb)。

You can also use ADO to get the data out, but to put it in another one, I would think you would need one of the ways listed above to do it (since you would need to reference the excel object). If you are using Excel 2007 and above you can also directly access the XML files and manipulate them that way (minus xlb, of course).

您还可以创建一个库从您执行文件并在本地复制它。 请参阅这里

You can also create a library from you execution file and copy it locally. See here.

对于标题,只需使用Dictionary(Of String,Integer)或List(Of String)来确定文件的索引是什么。

As for headers, just use a Dictionary(Of String, Integer) or List(Of String) to figure out what the index of the file(s) is.

这篇关于复制/映射excel扩展表之间的数据,Vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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