• / 8
  • 下载费用:10 金币  

VB操作Excel实现读取写入打印.doc

关 键 词:
VB操作Excel实现读取写入打印.doc
资源描述:
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 ThenDetailRes.MoveFirstFor row2 = 0 To DetailRes.RecordCount - 1Dim arrayProduct(50, 17) As StringarrayProduct(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.Fields(“opex“)arrayProduct(row2, 7) = DetailRes.Fields(“opex_per“) & “%“arrayProduct(row2, 8) = DetailRes.Fields(“oper_profit“)arrayProduct(row2, 9) = DetailRes.Fields(“oper_profit_per“) & “%“arrayProduct(row2, 10) = DetailRes.Fields(“dio“)arrayProduct(row2
展开阅读全文
  微传网所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。
0条评论

还可以输入200字符

暂无评论,赶快抢占沙发吧。

关于本文
本文标题:VB操作Excel实现读取写入打印.doc
链接地址:https://www.weizhuannet.com/p-9852766.html
微传网是一个办公文档、学习资料下载的在线文档分享平台!

微传网博客

网站资源均来自网络,如有侵权,请联系客服删除!

 网站客服QQ:80879498  会员QQ群:727456886

copyright@ 2018-2028 微传网络工作室版权所有

     经营许可证编号:冀ICP备18006529号-1 ,公安局备案号:13028102000124

收起
展开