VB 操作 EXCEL,实现数据写入以与数据组合1]定义 EXCEL 的一系列操作Dim xlApp As Excel.ApplicationDim ExcelShowStr As StringSet xlApp = CreateObject("Excel.Application")xlApp.Visible = trueAppLogFile.WriteLine (CStr(Date) & "_" & CStr(Time) & ":Set xlApp=new Excel.Application")Dim xlBook As WorkbookDim xlSheet As WorksheetDim xlrow, sheetIndex, sheetColumn As Integer'fileurl ="D:\VB 英迈\Template\WriteData.xls" Editable=空值Set xlBook = xlApp.Workbooks.Open(fileUrl, Editable) '打开 EXCEL 模板Set xlSheet = xlApp.ActiveSheet--------------------------------------------------------------------------------------------[2]写入数据的操作xlSheet.Range(xlSheet.Cells(beginRow, 1), xlSheet.Cells(endRow - 1, 1)).Merge '合并单元格xlSheet.Cells(beginRow, 1).FormulaR1C1 = CustName '单行插入xlSheet.Cells(beginRow, 1).VerticalAlignment = xlTop '垂直,写入数据的位置,这里为高 xlSheet.Cells(beginRow, 2).HorizontalAlignment = xlHAlignCenter '水平写入数据的位置,这里为居中 xlSheet.Range(xlSheet.Cells(beginRow, 1), xlSheet.Cells(endRow - 1, 19)).Font.ColorIndex = ConstModule.COLOR_BLUE '单元格的字体颜色xlSheet.Range(xlSheet.Cells(beginRow, 1), xlSheet.Cells(endRow - 1, 19)).Font.Bold = True '单元格的数据为粗体显示xlSheet.Range(xlSheet.Cells(beginRow, 1), xlSheet.Cells(endRow - 1, 19)).Interior.ColorIndex = ConstModule.COLOR_SILVER '单元格的背景颜色定义数组,一次性写入,列子如下:If DetailRes.RecordCount > 0 Then DetailRes.MoveFirst For row2 = 0 To DetailRes.RecordCount - 1 Dim arrayProduct(50, 17) As String arrayProduct(row2, 0) = DetailRes.Fields("Product") arrayProduct(row2, 1) = DetailRes.Fields("rev") arrayProduct(row2, 2) = DetailRes.Fields("sagm") arrayProduct(row2, 3) = DetailRes.Fields("sagm_per") & "%" arrayProduct(row2, 4) = DetailRes.Fields("gp") arrayProduct(row2, 5) = DetailRes.Fields("gp_per") & "%" arrayProduct(row2, 6) = DetailRes.Fiel...