This article originates from the network collection, if has the inappropriate place, please leave a message.
The first way:
Using OLE DB to get the data for an Excel file and then a dataset to SQL Server, this approach has the advantage of being flexible enough to do what the user needs for each cell in the Excel table.
string Connexcel = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + FilePath + "; Extended properties=excel 8.0 ";
The second way:
By means of COM components
The Third Way:
Through third-party plugins such as Aspose.cells
Aspose.Cells.Workbook Workbook = new Aspose.Cells.Workbook (); Workbook. Open (strFileName); Aspose.Cells.Worksheets wsts = workbook. worksheets; for (int i = 0; I<wsts. Count; i++) {Aspose.Cells.Worksheet WST= Wsts[i]; int MaxR= Wst. Cells.maxrow; int MaxC= Wst. Cells.maxcolumn; if (MaxR>0 && MaxC > 0) {DataTable dt = Wst. Cells.exportdatatableasstring (0, 0, MaxR + 1, MaxC + 1, true); Ds. Tables.add (DT); } }
C # import Excel three way, 64-bit machine does not support the first kind