第 1 步:创建一个名为“ClassFiles”的类
public class ClassFiles
{
private String fileName;
private String excelConnectionString;
public String getFileName()
return fileName;
public void setFileName(String fileName)
{
this.fileName=fileName;
}
public String getExcelConnectionString()
return excelConnectionString;
public void setExcelConnectionString(String excelConnectionString)
{
this.excelConnectionString=excelConnectionString;
}
}
第 2 步:在您的主类中,添加文件名以及 excelConnection 字符串,例如:
public class MainClass{
private void AddFilesToDB(List<ClassFiles>fileDetails){
for(ClassFiles fileDeteil : fileDetails){
using (OleDbConnection connection =
new OleDbConnection(fileDeteil.getExcelConnectionString))
{
connection.Open();
CheckNumeberOfSheets(connection);
}
// as well as u can get the file name..
String fileName=fileDeteil.getFileName();
}
}
public Static void main(string args[]){
List<ClassFiles> addDetails =new ArrayList<ClassFiles>();
//now add the no of files into the list
ClassFiles objFile1=new ClassFiles();
objFile1.setFileName("filename1");
objFile1.setExcelConnectionString("excelConnectionString1");
addDetails.add(objFile1);
ClassFiles objFile2=new ClassFiles();
objFile2.setFileName("filename2");
objFile2.setExcelConnectionString("excelConnectionString2");
addDetails.add(objFile2);
and so on..
then call the function for further process.,
new MainClass().AddFilesToDB(addDetails);
}
hope it ll help you..