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

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

ID:42745658

大小:54.51 KB

页数:8页

时间:2019-09-21

VB操作Excel实现读取写入打印_第1页
VB操作Excel实现读取写入打印_第2页
VB操作Excel实现读取写入打印_第3页
VB操作Excel实现读取写入打印_第4页
VB操作Excel实现读取写入打印_第5页
资源描述:

《VB操作Excel实现读取写入打印》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库

1、VB操作EXCEL,实现数据写入以及数据组合1】定义EXCEL的一系列操作DimxlAppAsExcel.ApplicationDimExcelShowStrAsStringSetxlApp=CreateObject("Excel.Application")xlApp.Visible=trueAppLogFile.WriteLine(CStr(Date)&"_"&CStr(Time)&":SetxlApp=newExcel.Application")DimxlBookAsWorkbookDimxlSheetAsWorksheetDimxlrow,sheetIndex,sheetColumnA

2、sInteger'fileurl="D:VB英迈TemplateWriteData.xls"Editable=空值SetxlBook=xlApp.Workbooks.Open(fileUrl,Editable)'打开EXCEL模板SetxlSheet=xlApp.ActiveSheet--------------------------------------------------------------------------------------------【2】写入数据的操作xlSheet.Range(xlSheet.Cells(beginRow,1),xlSheet.Cel

3、ls(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.ColorIn

4、dex=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'单元格的背景颜色定义数组,一次性写入,列子如下:IfDetailRes.RecordCount>0ThenDeta

5、ilRes.MoveFirstForrow2=0ToDetailRes.RecordCount-1DimarrayProduct(50,17)AsStringarrayProduct(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

6、.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)=Det

7、ailRes.Fields("dio")arrayProduct(row2,11)=DetailRes.Fields("dpo")arrayProduct(row2,12)=DetailRes.Fields("dso")arrayProduct(row2,13)=DetailRes.Fields("working_capital")arrayProduct(row2,14)=DetailRes.Fields(

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。