Home > Net >  The.net select files batch import EXCEl
The.net select files batch import EXCEl

Time:10-01

To be a function select the folder that contains multiple EXCEL, then import the EXCEL data,

CodePudding user response:

Please describe in detail your requirements, I also to have a look,

CodePudding user response:

First of all, the default HTML input type=file is not possible to select the folder. So if you're asked to select the folder so you can only use a third party controls.

After selected folder does not upload, third party components estimate also has this function.

As for import does not read after you upload the XLS also please use third party controls (npoi)

CodePudding user response:

refer to the second floor diaodiaop response:
default HTML input type=first file is not possible to select the folder. So if you're asked to select the folder so you can only use third-party control.

After selected folder does not upload, third party components estimate also has this function.

As for import does not read after you upload the XLS also use third party controls (npoi)

Excuse me, how to use c + + library npoi

CodePudding user response:

I made a c #, but it seems format to unity

CodePudding user response:

At the front desk to place a first FileUpload control used to select the file:
Style can edit it again; To define a button to import

Background:
Protected void btnImport_Click (object sender, EventArgs e)
{
//get the file name
String strFileName=fulImport. FileName;
//verification file type is Excel
If (strFileName. Substring (strFileName. LastIndexOf ('. '))!=". XLSX & amp;" & StrFileName. Substring (strFileName. LastIndexOf ('. '))!=". XLS ")
{
//prompt error message...
}
}

///& lt; summary>
///get the Excel data
///& lt;/summary>
///& lt; Param name="filePath & gt;" The path of the file & lt;/param>
///& lt; Returns>
Private DataSet GetExcelData (string strFilePath)
{
Try
{
//get the connection string
String strConn=GetOleDbConnectionString (strFilePath);

The DataSet ds=new DataSet ();
Using (OleDbConnection conn=new OleDbConnection (strConn))
{
//open the connection
Conn. The Open ();
System. Data. DataTable dt=conn. GetOleDbSchemaTable (OleDbSchemaGuid. Tables, new object [] {null, null, null, "TABLE"});

//Excel all worksheets in the workbook
System. Data. DataTable schemaTable=conn. GetOleDbSchemaTable (OleDbSchemaGuid. Tables, null);
OleDbDataAdapter sqlada=new OleDbDataAdapter ();

Foreach (DataRow Dr In schemaTable. Rows)
{
Try
{
String strSql="Select * From [" + Dr [2]. The ToString (). The Trim () +"] ".
If (strSql. The Contains (" $"))
{
OleDbCommand objCmd=new OleDbCommand (strSql, conn);
Sqlada. SelectCommand=objCmd;
Sqlada. The Fill (ds, Dr [2]. The ToString (). The Trim ());
}
}
Catch {}
}
//close the connection
Conn. Close ();
}
Return the ds;
}
The catch (Exception ex)
{
return null;
}
}



///& lt; summary>
///it is important to note that only if the target machine's operating system, is a 64 - bit,
///project needs to be compiled for x86, rather than simply use the default Any CPU.
///& lt;/summary>
///& lt; Param name="strExcelFileName & gt;"
///& lt; Returns>
Private string GetOleDbConnectionString (string strExcelFileName)
{
//Office 2007 and use the following version.
String strJETConnString=
The String. Format (" Provider=Microsoft. Jet. The OLEDB. 4.0; Data Source={0}; Extended Properties='Excel 8.0; HDR=Yes; IMEX=1; '", strExcelFileName);
//XLSX extension use.
String strASEConnXlsxString=
The String. Format (" Provider=Microsoft. ACE. The OLEDB. 12.0; Data Source={0}; Extended Properties=\ "Excel Xml 12.0; HDR=YES; IMEX=1; \ "", strExcelFileName);
//XLS extension use.
String strACEConnXlsString=
The String. Format (" Provider=Microsoft. ACE. The OLEDB. 12.0; Data Source={0}; Extended Properties=\ "Excel 8.0; HDR=YES \ "", strExcelFileName);
//other
String strOtherConnXlsString=
The String. Format (" Provider=Microsoft. Jet. The OLEDB. 4.0; Data Source={0}; Extended Properties='Excel 8.0; HDR=Yes; IMEX=1; '", strExcelFileName);

//try to use the ACE. If no error occurs, use the ACE driver.
Try
{
System. Data. The OleDb. OleDbConnection cn=new System. The Data. The OleDb. OleDbConnection (strACEConnXlsString);
Cn. The Open ();
Cn. The Close ();
//using the ACE
Return strACEConnXlsString;
}
The catch (Exception)
{
//start the ACE fail.
}

//try to use the Jet. If no error occurs, use the Jet driver.
Try
{
System. Data. The OleDb. OleDbConnection cn=new System. The Data. The OleDb. OleDbConnection (strJETConnString);
Cn. The Open ();
Cn. The Close ();
//using the Jet
Return strJETConnString;
}
The catch (Exception)
{
//start Jet failed.
}

//try to use the Jet. If no error occurs, use the Jet driver.
Try
{
System. Data. The OleDb. OleDbConnection cn=new System. The Data. The OleDb. OleDbConnection (strASEConnXlsxString);
Cn. The Open ();
Cn. The Close ();
//using the Jet
Return strASEConnXlsxString;
}
The catch (Exception)
{
//start Jet failed.
}
//if the ACE and JET fails, use the default JET.
Return strOtherConnXlsString;
}

CodePudding user response:

reference iron horse _ 7 floor response:
at the front desk to place a first FileUpload control used to select the file:
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related