The method of sample code portion Excel VBA operation

objExcelApp of createObject = SET ( "the Excel.Application") 
 2 objExcelApp.DisplayAlerts = to false 
 . 3 objExcelApp.Application.Visible = to false 
 . 4 objExcelApp.WorkBooks.add 
 . 5 SET objExcelBook = objExcelApp.ActiveWorkBook 
 . 6 SET objExcelSheets = objExcelBook.Worksheets 
 . 7 SET objSpreadsheet = objExcelBook .Sheets (. 1) 
 . 8
 . 9 Dim objField, iCol, iRow 
10 iCol. 1 = 'acquisition column number 
. 11 iRow =. 1' to obtain the line number 
12 is objSpreadsheet.Cells (iRow, iCol) .Value = "ASP by introducing the data in Access Excel file to - west network e ' "is inserted into the data cell 
13 is objSpreadsheet.Columns (iCol) = .ShrinkToFit to true' setting whether to automatically adapt to the size of the table cell (cell constant width) 
14'Font an Excel table 
15 objSpreadsheet.Cells (iRow, iCol) .Font.Bold = True' bold font cell 
16 objSpreadsheet.Cells (iRow, iCol) .Font.Italic = False 'cell italic 
. 17 objSpreadsheet .Cells (iRow, iCol) .Font.Size = 20 ' set the cell size 
18 is objSpreadsheet.Cells (iRow, iCol). 1 .ParagraphFormat.Alignment =' format the cell alignment setting: middle 
. 19 objspreadsheet.Cells (iRow, iCol) .font.name = "Arial" 'Font set the cell 
20 is objspreadsheet.Cells (iRow, iCol) .font.ColorIndex = 2' setting text color cell, the color can query, 2 as a white 
21 is objSpreadsheet.Range ( "A1 : F1 ") merge. 'merged cell (cell region) 
22 is A1 objSpreadsheet.Range (": Fl ") =. 1 Interior.ColorIndex.' background color network design unit 
23 is ' objSpreadsheet.Range (" A2: F2 of "). WrapText = true 'rewind character set (wrap)
24iRow=iRow+1 
25For Each objField in objRS.Fields 
26'objSpreadsheet.Columns(iCol).ShrinkToFit=true 
27objSpreadsheet.Cells(iRow, iCol).Value = objField.Name 
28'设置Excel表里的字体 
29objSpreadsheet.Cells(iRow, iCol).Font.Bold = True 
30objSpreadsheet.Cells(iRow, iCol).Font.Italic = False 
31objSpreadsheet.Cells(iRow, iCol).Font.Size = 20 
32objSpreadsheet.Cells(iRow, iCol).Halignment = 2 '居中 
33iCol = iCol + 1 

Reproduced in: https: //www.cnblogs.com/zhangchenliang/archive/2012/12/27/2836576.html

Guess you like

Origin blog.csdn.net/weixin_34127717/article/details/93495308