python实现读取excel数据并且绘制各种曲线图整合到vb.net开发的windowsform中

天蝎水水001 2020-01-09 07:00:37
请大家提供个思路或者路径
...全文
255 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_35503830 2020-01-10
  • 打赏
  • 举报
回复
直接用VB.net 读Excel,然后再用Vb.net 绘图. 最近刚好在做读excel的程序,给你个函数. vb.net 读 Excel ''' <summary> ''' 根据表名获取Excel内容。 ''' </summary> ''' <param name="sheetName">工作表名称,例:sheet1</param> ''' <param name="filePath">Excel的完整路径</param> ''' <param name="where">可选参数,筛选选择数据的范围,例"站名='哈尔滨'"</param> ''' <returns>在filepath中以sheetname为名字的工作表</returns> ''' <remarks></remarks> Public Shared Function GetTableFromExcel(sheetName As String, filePath As String, Optional where As String = "") As DataTable Dim connStrTemplate As String = String.Empty Dim fileType As String = System.IO.Path.GetExtension(filePath) If String.IsNullOrEmpty(fileType) Then Return Nothing Select Case fileType Case ".xlsx" connStrTemplate = "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & filePath & ";" & "Extended Properties='Excel 12.0;HDR=YES;IMEX=1'" Case ".xls" connStrTemplate = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & filePath & ";" & "Extended Properties='Excel 8.0;HDR=YES;IMEX=1'" Case Else Throw New Exception("文件格式有误") End Select Dim dt As DataTable = Nothing If (Not System.IO.File.Exists(filePath)) Then Return Nothing Dim conn As OleDbConnection = New OleDbConnection(String.Format(connStrTemplate, filePath)) Try conn.Open() If (sheetName Is Nothing OrElse sheetName.Trim().Length = 0) Then '如果表名不存在则获取第一个表. Dim schemaTable As DataTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, {Nothing, Nothing, Nothing, "TABLE"}) sheetName = schemaTable.Rows(0)("TABLE_NAME").ToString().Trim() End If Dim da As OleDbDataAdapter = Nothing Dim ds As DataSet = New DataSet() Dim strSQL As String = "Select * From [" & sheetName & "$]" If (Not String.IsNullOrWhiteSpace(where)) Then 'strSQL = "Select * From [" + sheetName + "$] where 站名='哈尔滨'" strSQL = String.Format("Select * From [" & sheetName & "$] Where {0}", where) End If Try da = New OleDbDataAdapter(strSQL, conn) da.Fill(ds) dt = ds.Tables(0) Catch er As Exception da = New OleDbDataAdapter("Select * From [sheet1$]", conn) da.Fill(ds) dt = ds.Tables(0) End Try Catch ex As Exception Throw ex Finally conn.Close() End Try Return dt End Function #End Region 绘图用chart控件,不是很难,网上例程也很多,随便找找 第一次回帖,有分没?

16,550

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧