Take a look at the DevExpress Spreadsheet Document Server (non-visual component with complete spreadsheet functionality available via its API). It allows developers to create, modify, save and print Excel documents, even when Microsoft Excel or Microsoft Office is not installed on the system. Supported File Formats - XLS, XLSX, XLSM, CSV and TXT;
how to extract the content of excel document with devexpress
-
07-07-2023 - |
Question
I would extract the content of excel document. It's possible with devexpress 13.2? Does anybody have any suggestion?
Thanks a lot in advance
La solution
Autres conseils
I have done an import of an excel-file to update a SQL server table in the last days (with the DevExpress Grid only to show the imported data).
I my example, I:
- ask the user for the filename (not necessary if you already know the file name and path)
- load the excel-file in a datatable (no devexpress needed for that)
- show the datatable in a DevExpress Grid then
Note: in real live, I use the grid only to view/control the loaded data.
I then update an existing datatable on a SQL server from the loaded data in the datatable (code not included here).
Note: In the example, the sheet name always is "Sheet1" - maybe you want to make the sheet name also variable for your scenario...
Note: You don't need DevExpress, if you only want to import an Excel file into a DataTable (see ImportTable = ReadExcelIntoDataTable(cFileName, "Sheet1") and function ReadExcelIntoDataTable()) in code below.
' Chose the Excel-File over Open FileDialog()
' If you don't know the filename & path allready
Dim cFileName As String = ""
Dim filedialog As OpenFileDialog = New OpenFileDialog()
filedialog.Title = "Chose the File"
filedialog.DefaultExt = ".XLSX"
filedialog.ShowDialog()
cFileName = filedialog.FileName
'
If Not cFileName = "" Then
ImportTable = ReadExcelIntoDataTable(cFileName, "Sheet1")
If ImportTable.Rows.Count > 0 Then
Grid_Datenimport.DataSource = ImportTable
' Do some format (if you like)..
GridView2.Columns("ColumnX").DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime
GridView2.Columns("ColumnX").DisplayFormat.FormatString = "dd/MM/yyyy HH:mm:ss"
GridView2.Columns("ColumnX").Width = 160
End If
End If
Public Shared Function ReadExcelIntoDataTable(ByVal FileName As String, ByVal SheetName As String) As DataTable
Dim RetVal As New DataTable
Dim strConnString As String
strConnString = "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" & FileName & ";"
Dim strSQL As String
strSQL = "SELECT * FROM [" & SheetName & "$]"
Dim y As New Odbc.OdbcDataAdapter(strSQL, strConnString)
y.Fill(RetVal)
Return RetVal
End Function