Home > Net >  Python implementation reading excel data and plot of a variety of integrated into the vb.net develop
Python implementation reading excel data and plot of a variety of integrated into the vb.net develop

Time:09-24

Please provide a train of thought or path

CodePudding user response:

With VB.net directly read Excel, and then drawing by VB.net.

Just doing recently read excel program, give you a function.
Vb.net read Excel

"' & lt; summary>
"' get to Excel content according to the name of the table,
"' & lt;/summary>
"' & lt; Param name="sheetName & gt;" Work table name, example: sheet1 & lt;/param>
"' & lt; Param name="filePath & gt;" Excel the full path & lt;/param>
"' & lt; Param name="where" & gt; The range of optional parameters, screening of selected data, case "name='Harbin'" & lt;/param>
"' & lt; returns> In the filepath sheetname to name the worksheet & lt;/returns>
"' & lt; Remarks>
Public Shared Function GetTableFromExcel (sheetName As String, As filePath String, Optional where As String="") As the DataTable
Dim connStrTemplate As String=String. The Empty
Dim fileType As String=System. IO. Path. GetExtension (filePath)
If the String. IsNullOrEmpty (fileType) Then Return Nothing
The Select Case fileType
Case ". XLSX "
ConnStrTemplate="Provider=Microsoft. ACE. The OLEDB. 12.0;" & "Data Source=" & amp; FilePath & amp; ";" & "Extended Properties='Excel 12.0; HDR=YES; IMEX=1 '"
Case ". XLS "
ConnStrTemplate="Provider=Microsoft. Jet. The OLEDB. 4.0;" & "Data Source=" & amp; FilePath & amp; ";" & "Extended Properties='Excel 8.0; HDR=YES; IMEX=1 '"
In Case the Else
Throw New Exception (" file format is wrong ")
End the Select
Dim As DataTable dt=Nothing
If (Not System. IO. File. The Exists (filePath)) Then Return Nothing

Dim conn As OleDbConnection=New OleDbConnection (String Format (connStrTemplate filePath))
Try
Conn. The Open ()
If (sheetName Is Nothing OrElse sheetName. The Trim (). The Length=0) Then 'If the name of the table does not exist for the first table.
Dim schemaTable As DataTable=conn. GetOleDbSchemaTable (OleDbSchemaGuid. Tables, {Nothing, Nothing, Nothing, "TABLE"})
SheetName=schemaTable. Rows (0) (" TABLE_NAME "). The ToString (). The Trim ()
End the If

Dim da As OleDbDataAdapter=Nothing
Dim ds As the DataSet=New DataSet ()
Dim strSQL As String="Select * From [" & amp; sheetName & amp;" $] "

If (Not String. IsNullOrWhiteSpace (where)) Then
StrSQL="Select * From [" + sheetName +" $] where name='Harbin' "
StrSQL=the String. Format (" Select * From [" & amp; sheetName & amp; "$] Where {0}", Where)
End the If
Try
Da=New OleDbDataAdapter (strSQL, conn.)
Da. The Fill (ds)
Dt=ds. Tables (0)
Catch the er As Exception
Da=New OleDbDataAdapter (" Select * From [sheet1 $] ", conn.)
Da. The Fill (ds)
Dt=ds. Tables (0)
End the Try
Catch the ex As Exception
Throw the ex
The Finally
Conn. Close ()
End the Try
Return dt
End the Function
# End Region


Drawing with the chart controls, not very hard, routines are many on the net, and take a look for

For the first time reply, there are points?
  • Related