/// <Summary>
/// Obtain Excel Data to dataset Jia Shiyi
/// </Summary>
/// <Param name = "FILENAME"> complete Excel file name </param>
/// <Param name = "isfirsttitle"> whether the first line is a title line </param>
/// <Returns> </returns>
Public static dataset getdatafromexcel (string filename, bool isfirsttitle)
{
Dataset DS = NULL;
String strconn = "provider = Microsoft. Ace. oledb.12.0; Data Source =" + filename + "; extended properties = 'excel"
+ (Filename. endswith ("xls", stringcomparison. currentcultureignorecase )? "8": "12") + ". 0; HDR =" + (isfirsttitle? "Yes": "no") + "'";
Using (oledbconnection conn = new oledbconnection (strconn ))
{
Conn. open ();
// Return the Excel schema, including the name, type, Creation Time, and modification time of each sheet.
Datatable dtsheetname = conn. getoledbschematable (oledbschemaguid. Tables, new object [] {null, "table "});
DS = new dataset ();
// String array containing the table name in Excel
For (int K = 0; k <dtsheetname. Rows. Count; k ++)
{
String strtablename = dtsheetname. Rows [k] ["table_name"]. tostring ();
String STR = "select * from [" + strtablename + "]";
Oledbdataadapter da = new oledbdataadapter (STR, Conn );
Da. Fill (DS, strtablename. Replace ("$", ""). tolower ());
Da. Dispose ();
}
If (! Isfirsttitle)
{
Foreach (datatable DT in DS. Tables)
{
For (Int J = 0; j <DT. Columns. Count; j ++)
{
DT. Columns [J]. columnname = J. tostring ();
}
}
}
Conn. Close ();
Conn. Dispose ();
}
Return Ds;
}
Welcome to: http: // 121.18.78.216, which is a demonstration platform for ease of query and analysis, workflow, content management, and project management.