作者: aribet.kuang   发表日期: 2007-10-18 13:18   复制链接




'重要方法   ImportSheet后面的参数说明:文件路径,global名字,global 谠祰$峡G  
Function WriteExcel() ﹕]6c9  
   Dim ExcelContent(3) Ra灤胷*  
   strFileName = "E:\cntesting.xls"  'Excel文件路径 衎ょ@秉  
   For j = 0 to 3 繽9{踅  
   ExcelContent(j) = "" 鍡7鈠$-`  
 Next

 ExcelContent(1) = DataTable("I_orderId", dtGlobalSheet) XVy4 +  
 ExcelContent(2) = DataTable("I_orderAmountEqual", dtGlobalSheet) !蛵嵧+2  
' 写数据到Excel文件 煉B@"6+蚬  
 Dim Obj, Look, Sheet EǐZ 盁蠏  
 Set Obj = CreateObject("Excel.Application")  *]昺Ej4  
 Obj.Application.Visible = True C杻P睻灹  
 Set Look = Obj.WorkBooks.Open(strFileName) ^w肾馆  
 Set Sheet = Look.Worksheets(1) rqL1濩?  
 For j = 1 to 2 DA彣8毰  
   Sheet.cells(2,j) = ExcelContent(j) Bt柌卧  
 Next 鯠w怐.&  
 Obj.DisplayAlerts = False t$[.鯅!K  
 Look.Close(True) 0訁罥  
 Obj.Quit b=/""  
 Set Obj = nothing !曣疙,U  
End Function

'--------------------------------------------------------------

'从Excel读数据 '2.鶀)>  
Function ReadExcel() 痕^R  
 datatable.AddSheet("Global")' è4:暬j  
 datatable.ImportSheet "E:\cntesting.xls","test","Global"

 Dim i,RowCount 3j铮y[  
 i=0 髈<婿b  
 RowCount=datatable.GetSheet("Global").GetRowCount ' 设置 RowCount 等于 Global中的行数。 ' *娉r譸  
 msgbox RowCount ~罵b:P  
 Do while i<rowcount v"雙唃|鋋b  
 i=i+1 Z_9*旿n  
 datatable.getsheet("Global") ' 8鶐$撳祮  
 datatable.setcurrentrow(i) 趛2毙:y  
 msgbox DataTable.GetSheet("Global").GetParameter(i).Value '取得第一列的值 D樾鹶挶D  
  f樽E痘j  
 datatable.setcurrentrow(n) N~ wN  
 msgbox Datatable.GetSheet("Global").GetParameter(i+1).Value '取得第二列的值 #應÷U {  
 msgbox datatable.getsheet("Global").getparameter("I_orderAmountEqual").RawValue'取得特定的I_orderAmountEqua列的值 g慧zV禶  
 loop 3鴘忴罻G  
End Function x$[z娡i  
WriteExcel   '写入函数调用 /ゾ繐姞  
ReadExcel    '读出函数调用



欢迎到 aribet.kuang 的个人主页看更多内容



  共0条回复