资源描述:
《vb创建excel表格,合并单元格,生成图形等操作》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、PrivateSubCommand4_Click()OnErrorResumeNext''''''''''''''''''''''''''''''''''''''''''''''''''''''''CreateExcelTable''''''''''''''''''''''''''''''''''''''''''DimxlAppAsExcel.ApplicationDimxlBookAsExcel.WorkbookDimxlSheetAsExcel.WorksheetDimxlSheet1AsExcel.WorksheetDimiAsInteger,tmHour
2、AsString''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''OnErrorResumeNext''''''''''''''''''''''''''''''''''''''''''''''''''''''''''SetxlApp=Excel.ApplicationSetxlBook=xlApp.Workbooks.Add'xlBook.ActivateSetxlSheet=xlBook.Worksheets(1)'''''''''''''''''''''''''''''''''引用第1张工
3、作表xlApp.ActiveSheet.Rows.VerticalAlignment=xlVAlignCenter'''''垂直方向居中xlApp.ActiveSheet.Rows.HorizontalAlignment=xlVAlignCenter'''水平方向居中xlSheet.Name="实测值"SetxlSheet1=xlBook.Worksheets(2)xlSheet1.Name="Chart"WithxlSheetFori=2To11.Range(Cells(1,1),Cells(1,i)).Merge''''''''''''''''''''合并A
4、-K单元格Next'.Cells(1,1).ForeColor=RGB(100,150,255).Cells(1,1).Font.Size=25''''''''''''''''''''''''''设置行高'设置列宽Fori=1To22.Rows(i).RowHeight=25NextFori=1To11.Columns(i).ColumnWidth=15Next'''''''''''''''''''''''''''合并单元格Fori=3To22Ifi<8Then.Range(Cells(3,1),Cells(i,1)).Merge'''''''''''合并A3-
5、A7单元格.Range(Cells(3,8),Cells(i,8)).Merge'''''''''''合并H3-H7单元格ElseIfi<13Then.Range(Cells(8,1),Cells(i,1)).Merge.Range(Cells(8,8),Cells(i,8)).MergeElseIfi<18Then.Range(Cells(13,1),Cells(i,1)).Merge.Range(Cells(13,8),Cells(i,8)).MergeElseIfi<23Then.Range(Cells(18,1),Cells(i,1)).Merge.Ra
6、nge(Cells(18,8),Cells(i,8)).MergeEndIfNext''''''''''''''''''''''''''''''''''''''''''''.Range("A1","K22").Borders.LineStyle=xlContinuous'''''''单元格边框.Range("A1","K22").Borders.Color=vbBlue'''''''''''''''''边框颜色.Range("A1","K22").Interior.Color=RGB(100,180,0)''''''区域背景色''''''''''''''''''
7、''''''''''''.Range("A1").Value="iWatt项目".Range("A1").Font.Color=vbRed''''''''''''''设置字体颜色.Range("A1").Font.Name="楷书"''''''''''''''设置字体字型.Range("A1").Font.Size=30''''''''''''''''''设置字体字号'''''''''''''''''''''''''''''''''''''''.Range("A2").Value="输入电压(VAC)".Range("B2").Value="输入功率(W)".R
8、ange("C2").V