unity读取文件夹下所有的excel 表格并还写成txt文件
时间: 2023-05-12 19:07:10 浏览: 204
你可以使用C#中的Directory类和ExcelDataReader库来读取文件夹下的所有Excel表格,并将数据写入txt文件中。以下是示例代码:
```
using System.IO;
using ExcelDataReader;
string folderPath = "your/folder/path";
string outputPath = "your/output/path/output.txt";
// Get all Excel files in the folder
string[] excelFiles = Directory.GetFiles(folderPath, "*.xlsx");
// Loop through each Excel file and read data
foreach (string excelFile in excelFiles)
{
using (var stream = File.Open(excelFile, FileMode.Open, FileAccess.Read))
{
using (var reader = ExcelReaderFactory.CreateReader(stream))
{
// Read data from the Excel file
while (reader.Read())
{
// Write data to the output file
using (StreamWriter writer = new StreamWriter(outputPath, true))
{
for (int i = 0; i < reader.FieldCount; i++)
{
writer.Write(reader.GetValue(i) + ",");
}
writer.WriteLine();
}
}
}
}
}
```
这段代码将读取指定文件夹下的所有.xlsx文件,并将数据写入指定的txt文件中。你可以根据需要修改文件路径和文件格式。
阅读全文