婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > Vbscript生成Excel報表的常用操作總結

Vbscript生成Excel報表的常用操作總結

熱門標簽:地圖標注政府哪個部門管 如何用機器人進行電銷 百度地圖標注點距離代碼 哪里有便宜的地圖標注公司 除了地圖標注還有這種生意嗎 神行者美術館地圖標注 佛山真人電銷機器人廠家 東營快遞外呼系統 齊齊哈爾高德地圖標注店

使用QTP自動化測試結束后,經常需要將測試結果寫入Excel中,這里就把一些常用對Excel操作的方法進行歸納、整理,方便使用時查閱。支持Office Excel 2003版本,不支持2007版本。

Vbscript代碼

On Error Resume Next
 Dim FileName, SheetName, Text, ExcelApp, ExcelBook, ExcelSheet
 FileName = "D:/Book1.xls"
 SheetName = "新建表"
 Text = "Hello QTP ! 你好, QuickTestProfessional !"
Set ExcelApp = CreateObject("Excel.Application")
 Set ExcelBook= ExcelApp.Workbooks.Open(FileName)
 Set ExcelSheet = ExcelBook.Sheets.Add '插入工作表
 'Set ExcelSheet = ExcelBook.Sheets.Item(SheetName) '獲得指定工作表
' *************** 對數據表的操作 ***************
 For i=1 To ExcelBook.Sheets.Count
 If ExcelBook.Sheets(i).Name=SheetName Then
 ExcelApp.DisplayAlerts=False
 ExcelBook.Sheets(i).Delete '刪除工作表
 ExcelApp.DisplayAlerts=True
 Exit For
 End If
 Next
 ExcelSheet.Name = SheetName '重命名工作表
' *************** 對文字的操作 ***************
 ExcelSheet.Cells(1,2) = Text
 ExcelSheet.Range("B2","B20").Value = Text
 ExcelSheet.Cells(1,2).Font.Name = "Verdana" '設置字體
 ExcelSheet.Cells(1,2).Font.Size = 25 '設置字號
 ExcelSheet.Cells(1,2).Font.Color = RGB(0, 0, 255) '設置字體顏色
 ExcelSheet.Cells(2,2).Font.Bold = True '文字加粗
 ExcelSheet.Cells(3,2).Font.Italic = True '文字傾斜
 ExcelSheet.Cells(4,2).Font.Underline = True '文字加下劃線
 ExcelSheet.Cells(5,2).Font.Strikethrough = True '文字加刪除線
 ExcelSheet.Cells(6,2).Characters(2, 2).Font.Superscript = True '設定文字上標
 ExcelSheet.Cells(7,2).Characters(2, 2).Font.Subscript = True '設定文字下標
' *************** 對單元格的操作 ***************
 ExcelSheet.Columns("B").ColumnWidth = 40 '設置列寬
 'ExcelSheet.Columns("B").AutoFit '自動調整列寬
 ExcelSheet.Range("B11").RowHeight=40 '設置行高
 'ExcelSheet.Rows(11).Rows.AutoFit '自動調整行高
 ExcelSheet.Range("B8","D8").Merge '合并單元格,水平方向
 ExcelSheet.Range("B18","B19").Merge '合并單元格,垂直方向
 ExcelSheet.Range("B8","D8").Borders.Color = RGB(0,255,0) '設定單元格邊框顏色
 ExcelSheet.Range("B12").Interior.Color = RGB(255,0,0) '設置單元格背景色
 ExcelSheet.Cells(9,2).WrapText = True '自動換行
 ExcelSheet.Cells(10,2).HorizontalAlignment = 3 '設置水平對齊,1常規,2靠左,3居中,4靠右
 ' 5填充,6兩端對齊,7跨列居中,8分散對齊
 ExcelSheet.Cells(11,2).VerticalAlignment = 1 '設置垂直對齊,1靠上,2居中,3靠下
 ' 4兩端對齊,5分散對齊
 ExcelSheet.Range("B14").Borders(1).LineStyle=1 '設置左邊框樣式
 ExcelSheet.Range("B14").Borders(2).LineStyle=2 '設置右邊框樣式
 ExcelSheet.Range("B14").Borders(3).LineStyle=3 '設置上邊框樣式
 ExcelSheet.Range("B14").Borders(4).LineStyle=4 '設置下邊框樣式
 ExcelSheet.Range("B15").ClearContents '清除單元格內容
 ExcelSheet.Range("B16").Formula="=1+10" '設置單元格公式
 ExcelSheet.Range("B17").AddComment("Hello"  vbLf  "QTP") '插入批注
 ExcelSheet.Range("B17").Comment.Visible=True '顯示批注
 'ExcelSheet.Range("B17").ClearComments '清除批注,與刪除批注效果相同
 'ExcelSheet.Range("B17").Comment.Delete '刪除批注,與清除批注效果相同
 'ExcelSheet.SaveAs("D:\Book2.xls") '另存為
ExcelBook.Save
 ExcelBook.Close
 ExcelApp.Quit
 Set ExcelBook = Nothing
 Set ExcelApp = Nothing
 SystemUtil.CloseProcessByName "Excel.exe" '如果仍有Excel.exe進程,可使用這句關閉進程
 If Err.number>0 Then
 MsgBox Err.Description
 End If
 On Error GoTo 0

補充:

ExcelApp.DisplayAlerts = False ‘關閉兼容性檢查
ExcelBook = ExcelApp.Workbooks.Add ‘新建Excel
ExcelSheet = ExcelBook.ActiveSheet ‘激活第一個表
ExcelSheet.Columns(“A:E”).AutoFit() ‘設置A到E列自動調整列寬
ExcelBook.SaveAs(“D:\Book2.xls”,FileFormat:=Excel.XLFileFormat.xlAddIn) ‘文件另存為

標簽:湖州 文山 四平 海口 鶴壁 邢臺 西安 銅川

巨人網絡通訊聲明:本文標題《Vbscript生成Excel報表的常用操作總結》,本文關鍵詞  Vbscript,生成,Excel,報表,的,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Vbscript生成Excel報表的常用操作總結》相關的同類信息!
  • 本頁收集關于Vbscript生成Excel報表的常用操作總結的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 北流市| 江北区| 鄂托克前旗| 新河县| 玉林市| 茶陵县| 前郭尔| 翁牛特旗| 鲁甸县| 浙江省| 余庆县| 奉节县| 永济市| 大洼县| 泽库县| 怀化市| 黔西县| 新龙县| 沙雅县| 平罗县| 蛟河市| 松江区| 竹溪县| 孟连| 集贤县| 陆川县| 长岭县| 花莲市| 通许县| 新平| 合水县| 和平县| 兰考县| 闽侯县| 海原县| 上杭县| 吴堡县| 临漳县| 通江县| 永仁县| 惠州市|