资源描述:
《VB创建Excel表格,合并单元格,生成图形等操作.doc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、PrivateSubCommand4_Click()OnErrorResumeNext''''''''''''''''''''''''''''''''''''''''''''''''''''''''CreateExcelTable''''''''''''''''''''''''''''''''''''''''''DimxlAppAsExcel.ApplicationDimxlBookAsExcel.WorkbookDimxlSheetAsExcel.WorksheetDimxlSheet1AsExcel.Wo
2、rksheetDimiAsInteger,tmHourAsString''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''OnErrorResumeNext''''''''''''''''''''''''''''''''''''''''''''''''''''''''''SetxlApp=Excel.ApplicationSetxlBook=xlApp.Workbooks.Add'xlBook.ActivateSetxlSheet=xlBoo
3、k.Worksheets(1)'''''''''''''''''''''''''''''''''引用第1张工作表xlApp.ActiveSheet.Rows.VerticalAlignment=xlVAlignCenter'''''垂直方向居中xlApp.ActiveSheet.Rows.HorizontalAlignment=xlVAlignCenter'''水平方向居中xlSheet.Name="实测值"SetxlSheet1=xlBook.Worksheets(2)xlSheet1.Name="Char
4、t"WithxlSheetFori=2To11.Range(Cells(1,1),Cells(1,i)).Merge''''''''''''''''''''合并A-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=
5、15Next'''''''''''''''''''''''''''合并单元格Fori=3To22Ifi<8Then.Range(Cells(3,1),Cells(i,1)).Merge'''''''''''合并A3-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)).MergeElse
6、Ifi<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.Range(Cells(18,8),Cells(i,8)).MergeEndIfNext''''''''''''''''''''''''''''''''''''''''''''.Range("A1","K22").Borders.LineStyle
7、=xlContinuous'''''''单元格边框.Range("A1","K22").Borders.Color=vbBlue'''''''''''''''''边框颜色.Range("A1","K22").Interior.Color=RGB(100,180,0)''''''区域背景色''''''''''''''''''''''''''''''.Range("A1").Value="iWatt项目".Range("A1").Font.Color=vbRed''''''''''''''设置字体颜色.Range
8、("A1").Font.Name="楷书"''''''''''''''设置字体字型.Range("A1").Font.Size=30''''''''''''''''''设置字体字号'''''''''''''''''''''''''''''''''''''''.Range("A2").Value="输入电压(VAC)".Range("B2").Value="输入功率(W)".Range("C2").V