首页 vb操作excel作图

vb操作excel作图

举报
开通vip

vb操作excel作图vb操作excel作图 Private Sub Command1_Click() Dim xlapp As Object 'New Excel.Application Dim xlBook As Object 'New Excel.Workbook Dim xlSheet As Object 'New Excel.Worksheet Set xlapp = CreateObject("Excel.Application") xlapp.Workbooks.Add xlapp.Visible = flase ...

vb操作excel作图
vb操作excel作图 Private Sub Command1_Click() Dim xlapp As Object 'New Excel.Application Dim xlBook As Object 'New Excel.Workbook Dim xlSheet As Object 'New Excel.Worksheet Set xlapp = CreateObject("Excel.Application") xlapp.Workbooks.Add xlapp.Visible = flase xlapp.Cells(1, 1) = "shiduan" xlapp.Cells(1, 2) = "datetime" xlapp.Cells(1, 3) = "x" xlapp.Cells(1, 4) = "y" xlapp.Cells(1, 5) = "x_t" xlapp.Cells(1, 6) = "y_t" xlapp.ActiveWorkbook.SaveAs App.Path + "\data.xls" xlapp.Workbooks.Close xlapp.Quit Set xlapp = Nothing End Sub Private Sub Command2_Click() Dim count As Integer Dim count_b As Integer Set xlapp = CreateObject("Excel.Application") xlapp.Visible = True On Error Resume Next Set xlBook = xlapp.Workbooks.Open(App.Path + "\data.xls") Set xlSheet = xlBook.Worksheets(1) xlSheet.Application.WindowState = xlMaximized xlSheet.Activate count = 11 xlSheet.Range("C2").Select xlSheet.Cells(2, 3).FormulaR1C1 = "=VALUE(RC[+2])" xlSheet.Range("C2").AutoFill Destination:=xlSheet.Range("C2:C" & 11), Type:=xlFillDefault xlSheet.Range("D2").Select xlSheet.Cells(2, 4).FormulaR1C1 = "=VALUE(RC[+2])" xlSheet.Range("D2").AutoFill Destination:=xlSheet.Range("D2:D" & 11), Type:=xlFillDefault count_b = 2 xlSheet.Range("C2 :D11").Select '选取区域 xlapp.Charts.Add xlapp.ActiveChart.SeriesCollection(2).Delete xlapp.ActiveChart.SeriesCollection(1).XValues = "=Sheet1!R" & count_b & "C3:R" & count & "C3" 'X区域 xlapp.ActiveChart.SeriesCollection(1).Values = "=Sheet1!R" & count_b & "C4:R" & count & "C4" 'Y区域 xlapp.ActiveChart.ChartType = xlXYScatter '设置散点 xlapp.ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("C" & count_b & ":D" & count) '选取区域 xlapp.ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1" With xlapp.ActiveChart.Axes(xlCategory) 'X轴 .MinimumScale = 0 '设置最小坐标 End With With xlapp.ActiveChart.Axes(xlValue) 'Y轴 .MinimumScale = 0 'Int(min_f(a) / 100) * 1000 + 50 '设置最小坐标 .CrossesAt = 0 'Int(min_f(a) / 100) * 1000 + 50 End With xlapp.ActiveChart.SeriesCollection(1).Select With Selection .MarkerStyle = xlMarkerStyleDiamond End With xlapp.ActiveChart.SeriesCollection(1).Trendlines.Add(Type:=xlPolynomial, Order:=3, Forward:=0, Backward:=0, DisplayEquation:=True, DisplayRSquared:=False).Select ' ' xlapp.ActiveChart.ChartArea.Select With xlapp.ActiveChart '设置标题和坐标名称 .HasTitle = True .ChartTitle.Characters.Text = "负荷气象分布图" '标题 .Axes(xlCategory, xlPrimary).HasTitle = True .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "实感指数" 'X 轴 .Axes(xlValue, xlPrimary).HasTitle = True .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "最大负荷(MW)" 'Y轴 End With ' xlapp.ActiveChart.HasLegend = True '图 关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf 图例 ' xlapp.ActiveChart.Legend.Select xlapp.ActiveChart.Legend.Position = xlTop '图例位置 ' xlapp.ActiveChart.ChartArea.Select ' xlapp.ActiveChart.PlotArea.Select xlapp.ActiveChart.PlotArea.ClearFormats ' xlapp.ActiveChart.Axes(xlValue).MajorGridlines.Select With xlapp.ActiveChart.Axes(xlValue).MajorGridlines.Border '虚线 .ColorIndex = 57 .Weight = xlHairline .LineStyle = xlDot End With '' xlapp.ActiveChart.ChartArea.Select ' xlapp.ActiveChart.SeriesCollection(1).Trendlines(1).Select '趋势线大小,颜色 With xlapp.ActiveChart.SeriesCollection(1).Trendlines(1).Border ' .ColorIndex = curv_color '3 .Weight = xlThick 'xlThick .LineStyle = xlGray75 End With With xlapp.ActiveChart.SeriesCollection(1).Trendlines(1) .Name = "回归负荷" '曲线名称 End With ' xlapp.ActiveChart.ChartArea.Select xlapp.ActiveChart.SeriesCollection(1).Name = "=""实际负荷""" '散点名称 xlapp.ActiveChart.PlotArea.Select '调整区域大小,先选中区域 xlapp.Selection.Left = 15 xlapp.Selection.Top = 55 xlapp.Selection.Height = 170 xlapp.Selection.Width = 343 xlapp.ActiveChart.SeriesCollection(1).Trendlines(1).DataLabel.Select '回归函数位置 xlapp.Selection.Left = 50 xlapp.Selection.Top = 35 ' xlapp.Selection.AutoScaleFont = True xlapp.ActiveChart.Legend.Select '标示调整 xlapp.Selection.Left = 99 xlapp.Selection.Top = 18 xlapp.ActiveChart.ChartTitle.Select '标题 xlapp.Selection.Top = 0 xlapp.ActiveSheet.Shapes("图表 1").ScaleHeight 0.8, msofalse, msoScaleFromTopLeft ' xlapp.ActiveChart.ChartArea.Select ' xlapp.Selection.AutoScaleFont = False xlapp.ActiveChart.Export App.Path + "\" + "SHIL" + ".jpg", "jpg" '导出图片 '' ''' xlapp.ActiveChart.Export App.Path + "\R\" + "SHILI" + ".jpg", "jpg" xlBook.Save xlBook.Close xlapp.Quit Set xlapp = Nothing Set xlBook = Nothing Set xlSheet = Nothing DoEvents End Sub
本文档为【vb操作excel作图】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_833902
暂无简介~
格式:doc
大小:22KB
软件:Word
页数:0
分类:互联网
上传时间:2017-10-17
浏览量:49