Linqtoexcel迭代excel文件和进程的行 [英] Linqtoexcel to iterate through rows of an excel file and process
问题描述
我有一个excel文件,用于批处理XML文件。该过程制作XML文件的副本。
在excel文件中。有一个文件名列表。
如果文件名与前一行匹配,那么它会将副本附加到同一文件中,否则将创建一个带文件名的新文件。
我正在考虑获取每一行的值并进行处理。 (我不是正确的做法)
但是,我确信如何去做。我能够通过列名功能获得第一列的列名。
我尝试过的方法:
I have an excel file which is used to batch process an XML file. the process makes a copy of the XML file.
In the excel file. There's a list of file names.
if the file name matches the previous row then it'll append the copy in the same file or if not then will create a new file with the file name.
I am thinking of getting the values of each row and process it. (I am not even if its the right way of doing it)
However, I am sure how to go about doing that. I was able to get column names of the first column via column names function.
What I have tried:
var excelFile = new ExcelQueryFactory(excelPath);
IQueryable<Row> excelSheetValues = from workingSheet in excelFile.Worksheet(sheetName) select workingSheet;
string[] headerRow = excelFile.GetColumnNames(sheetName).ToArray();
推荐答案
我不清楚你想要完成什么。但您肯定使用C#来获取行数据,使用类似于以下内容的代码:
I am not exactly clear on what you are trying to accomplish. But you certainly use C# to fetch row data using a code similar to the following:
private void LoadData()
{
OleDbConnection con = new OleDbConnection();
try
{
String strConnectionString = @"Provider = Microsoft.Jet.OLEDB.4.0; Mode = 16; Data Source = " + System.Configuration.ConfigurationSettings.AppSettings["DatabaseLocation"] + "; Extended Properties = " + "\"Excel 8.0;\"";
con.ConnectionString = strConnectionString;
OleDbCommand cmdFetchExistingRecord = new OleDbCommand();
cmdFetchExistingRecord.Connection = con;
DataSet dataSet = new DataSet();
cmdFetchExistingRecord.CommandText = "SELECT * FROM MyTable";
OleDbDataAdapter oleDbDataAdapter = new OleDbDataAdapter(cmdFetchExistingRecord);
con.Open();
oleDbDataAdapter.Fill(dataSet, "hData");
if (dataSet.Tables[0].Rows.Count > 0)
{
txtAgency_State.Text = DecryptData(dataSet.Tables[0].Rows[0]["Agency_State"].ToString());
}
else
{
}
}
catch
{
MessageBox.Show("An unexpected error occurred.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
con.Close();
}
}
我建议你阅读: C#:使用LinqToExcel查询Excel和.CSV文件 [ ^ ]
您的问题不明确,因此我无法提供有关LinqToExcel的更多详细信息。
I'd suggest to read this: C#: Query Excel and .CSV Files Using LinqToExcel[^]
Your question is not clear, so i cannot provide more details about LinqToExcel.
这篇关于Linqtoexcel迭代excel文件和进程的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!