根据excel数据处理文件。 [英] Processing file according to excel data.

查看:99
本文介绍了根据excel数据处理文件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过读取excel文件来处理文件的查找和替换。 excel文件的结构是这样的。



我尝试过:



这就是我的程序的结构。

I want to process find and replace on a file by reading the excel file. the excel file is structured this way.

What I have tried:

This is how my program is structured.

推荐答案

读取excel文件非常简单。您可以使用OleDbConnection创建与它的连接,然后使用OleDbCommand读取数据。例如,请查看阅读Excel文件使用C#进入ASP.NET中的DataSet [ ^ ]



将数据输入数据表之后,循环遍历行并创建输出。在伪代码中,一个非常简单的方法可能是 b
Reading the excel file is quite straightforward. You can use OleDbConnection to create a connection to it and then read the data using OleDbCommand. For example, have a look at Read Excel File into DataSet in ASP.NET Using C#[^]

After you have got the data into the datatable, loop through the rows and create the output. In pseudo code, a very simple approach could be
for each row in excel data table
   open file(row[0]) for apppend
   replace string(row[0]) with ...
   // other replacements if any
   close file
next row



当然,如果几行之间的文件相同,那么代码会不必要地打开和关闭同一个文件,这样你就可以根据需要进行优化。


Of course that code unnecessarily opens and closes the same file if the file is the same between several rows so you can optimize that if needed.


这篇关于根据excel数据处理文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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