1,与EXCEL连接方式:
OLEObject ExcelServer
ExcelServer = CREATE OLEObject
IF ExcelServer.ConnectToNewObject( "excel.application" ) < 0 THEN
messagebox('', "连接excel失败,检查你的系统是否安装了office,必须安装EXCLE才可以使用该导入功能!")
return
End if
2,常用操作:
ExcelServer.Workbooks.Open('e:/0pb/saveas.xls')
ExcelServer.activeworkbook.worksheets(2).activate
ExcelServer.activeworkbook.worksheets(2).cells(1,1).NumberFormat = 'yyyy/mm/dd'
// .cells[1,1].Font.Size = 20
// .cells[1,1].Font.name = "宋体"
// .cells[1,1].Font.bold = true
// .cells[1,1].HorizontalAlignment = 3
// .cells(1,1).Columns.AutoFit// 自动调整字段宽度
// .Range("D6").Formula = "=SUM(D25)" // 设置公式
ExcelServer.activeworkbook.worksheets(2).cells[1,1].Font.italic = true
ExcelServer.activeworkbook.worksheets(2).cells[1,1].Font.ColorIndex = 7
ExcelServer.activeworkbook.worksheets(2).cells[1,1].HorizontalAlignment = 3 //对其方式 1居左3居中4居右
ExcelServer.activeworkbook.worksheets(2).cells[1,1].value = '我们是中国人'
ExcelServer.activeworkbook.worksheets(2).Range("c5:d9").Select
ExcelServer.activeworkbook.worksheets(2).Range("c5:d9").MergeCells = True //合并单元格
ExcelServer.activeworkbook.worksheets(2).Range("c5:d9").RowHeight = 20//设置行高
//绘制边框
//选定的单元格左边框
ExcelServer.activeworkbook.worksheets(2).Range("c5:d9").Borders(1).LineStyle = 1 // 2边框为虚线
//选定的单元格右边框
ExcelServer.activeworkbook.worksheets(2).Range("c5:d9").Borders(2).LineStyle = 1 //
//选定的单元格上边框
ExcelServer.activeworkbook.worksheets(2).Range("c5:d9").Borders(3).LineStyle = 1 //
//选定的单元格下边框
ExcelServer.activeworkbook.worksheets(2).Range("c5:d9").Borders(4).LineStyle = 1 //
//保存
excelserver.activeworkbook.save
excelserver.activeworkbook.saveas('e:/0pb/temp.txt',3)
3,退出Excel连接:
excelserver.displayalerts=FALSE
ExcelServer.quit()
ExcelServer.DisconnectObject()
DESTROY ExcelServer