且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检索excel文件名

更新时间:2022-12-28 15:56:45

你使用 System.IO.tory.GetFiles(path \\to\\files)。这会将一个字符串数组返回给文件名。
You use the System.IO.tory.GetFiles("path\\to\\files"). That return a string array to file names.


我必须遗漏一些大的东西或者你不理解你应该写的代码。



我不明白你为什么在检索文件名时遇到问题,因为这段代码正在创建文件,而且为了创建文件,代码会给出文件名。

在这里,您在创建文件之前构建完整的文件名:

I must be missing something big or you don't understand the code you supposed to have written.

I don't understand why you have a problem retrieving the file names, because this code is creating the files, and to create the files, the code gives the file names.
Here, you build the full file name before creating the file:
string filePath = @"C:\Users\God\Desktop\DataDump\" + j + "Excel.xls";



路径 C:\ Users \ God \Desktop \ DataDump \

文件名为 j +Excel

扩展名为。xls



Nota:您的代码很复杂,可以简化为:


The path is C:\Users\God\Desktop\DataDump\
The file name is j + "Excel"
The extension is ".xls"

Nota: your code is complicated and can be simplified to:

for (int i = 0; i < reader.FieldCount; i++)
{
    sw_In.AutoFlush = true;
    sw_In.Write(reader.GetName(i) + "\t");
}
sw_In.Write("\n");
while (reader.Read())
{
    for (int i = 0; i < reader.FieldCount; i++)
    {
        sw_In.AutoFlush = true;
        sw_In.Write(reader[i].ToString() + "\t");
    }
    sw_In.Write("\n");
}