As shown in figure, the filling time is a second value, but after through code access, read within seconds, only to the minutes, such problems can lead to the back of the calculation, have to read the second,
Let users change text format,
Is there any way to solve this problem?
Code:
public static DataSet ExcelToDS (string file)
{
//string strConn="Provider=Microsoft. Jet. The OLEDB. 12.0;" + "Data Source=" + Path + ";" + "Extended Properties=8.0 Excel; HDR=NO. IMEX=1 '";
String connstring="";
String filetype=file. The Substring (file. The LastIndexOf ('. ') + 1);
The DataSet dt=null;
If (filetype. ToLower ()=="XLSX")
{
//Office 7 and above version not the presence of redundant space and the semicolon note
Connstring="Provider=Microsoft. ACE. The OLEDB. 12.0. Data Source="+ file +"; Extended Properties='Excel 8.0; HDR=NO. IMEX=1 '";
}
The else//if (filetype. ToLower ()=="XLS")
{
//Office 7 the following version
Connstring="Provider=Microsoft. JET. The OLEDB. 4.0. Data Source="+ file +"; Extended Properties='Excel 8.0; HDR=NO. IMEX=1 '";
}
Using (OleDbConnection conn=new OleDbConnection (connstring))
{
Conn. The Open ();
The DataTable schemaTable=conn. GetOleDbSchemaTable (System) Data. The OleDb. OleDbSchemaGuid. Tables, null);
//string tableName=schemaTable. Rows [0] [2]. The ToString (). The Trim ();
String tableName="sheet1 $";
String strExcel="";
OleDbDataAdapter myCommand=null;
StrExcel="select * from [" + tableName +"] ".
MyCommand=new OleDbDataAdapter (strExcel connstring);
Dt=new DataSet ();
MyCommand. The Fill (dt, "table1");
Conn. Close ();
Return dt.
}
}
CodePudding user response:
Try a different way, using npoi readCodePudding user response: