2023年11月29日发(作者:)pb操作EXCEL的一个对象 (/yyoinge/article/details/6549193) 以下内容保存为nvo_文件,再导入即可 view plaincopy to clipboardprint?$PBExportHeader$nvo_ forward global type nvo_excel from nonvisualobject end type end forward global type nvo_excel from nonvisualobject end type global nvo_excel nvo_excel type variables oleobject excel end variables forward prototypes public function integer of_connect () public function integer of_disconnect () public function string of_splitpath (string as, integer ai) public function integer of_check () public function string of_getvalue (string as_path, string as_sheet, long row, long col) public function string of_get_excel_colid (long al) public function long of_get_num_colid (string as) public function string of_getvalue (string as_path, integer ai_sheet, long row, long col) public function string of_getvalue (string as_path, string as_sheet, string as_row, long col) public function string of_getvalue (string as_path, integer ai_sheet, string as_row, long col) public function long of_insertrow (string as_path, string as_sheet, long row) public function string of_sheetname (string as_path, integer ai_sheet) public function long of_colcount (string as_path, string as_sheet) public function long of_rowcount (string as_path, string as_sheet) public function long of_sheetcount (string as_path) public function string of_find (string as_path, string as_sheet, integer ai_column, string as_find) public function boolean of_is_opened (string as_path) public function integer of_check (string as_path) public function integer of_workbookcount () public function integer of_check (string as_path, string as_sheetname) public function long of_sheetadd (string as_path, string as_sheet, integer ai_pos) public function boolean of_is_sheet_exists (string as_path, string as_sheet) public function integer of_open (string as_path) public function integer of_openwithsheet (string as_path, string as_sheet) public function integer of_close (string as) public function integer of_closewithsave (string as) public function integer of_save (string as)
x0cpublic function integer of_deletehypelink (string as_path, string as_sheet) public function integer of_openwithsheet (string as_path, integer ai_sheet) public function integer of_set_hypelink (string as_path, string as_sheet, long row, long col, string as_hype) public function integer of_setvalue (string as_path, integer ai_sheet, long row, long col, string as_value) public function integer of_setvalue (string as_path, string as_sheet, long row, long col, string as_value) public function integer of_sheetselect (string as_path, integer ai_sheet) public function integer of_sheetselect (string as_path, string as_sheet) public function integer of_show (boolean ab_show) public function integer of_showalldata (string as_path, string as_sheet) public function integer of_quit () public function integer of_sheetdelete (string as_path, string as_shee
t) public function long of_get_firstemprow (string as_path, string as_sheet, long al_col[]) public function integer of_setvalue (string as_path, integer ai_sheet, long row, string as_col, string as_value) public function integer of_setvalue (string as_path, string as_sheet, long row, string as_col, string as_value) public function string of_relative_path (string a1, string a2) public function integer of_scrollrow (string as_path, string as_sheet, long row) public function integer of_scrollcolumn (string as_path, string as_sheet, long col) public subroutine of_speed_set (string as_path, string as_sheet, any ast) end prototypes public function integer of_connect ();of_disconnect() int excelok excel=create oleobject; excelok=ttonewobject("ation"); if excelok<>0 then choose case excelok case -1 messagebox('错误提示接返回-1就好了 return -1 end try return 1 end function public function integer of_setvalue (string as_path, integer ai_sheet, long row, long col, string as_value);//设置单元格的内容 if of_check() < 0 then return -1 return of_setvalue(as_path, of_sheetname(as_path, ai_sheet), row, col, as_value) end function public function integer of_setvalue (string as_path, string as_sheet, long row, long col, string as_value);//设置单元格的内容 if of_check(as_path,as_sheet) < 0 then return -1 try oks(of_splitpath(as_path, 2)).sheets(as_sheet).cells(row, col).value = as_value catch( runtimeerror er) //出错的原因可能是工作簿并没有打开,直接返回-1就好了 return -1
x0cend try return 1 end function public function integer of_sheetselect (string as_path, integer ai_sheet);//切换到sheet, 前提是as已经打开 if of_check(as_path) < 0 then return -1 s(of_splitpath(as_path, 2)).Activate try (ai_sheet).Select////选择文件中一个工作表(按序号选择, 比较通用的选择) catch( runtimeerror er) //出错的原因可能是工作簿并没有打开,直接返回-1就好了 return -1 end try return 1 end function public function integer of_sheetselect (string as_path, string as_sheet);//切换到sheet, 前提是as已经打开 if of_check(as_path,as_sheet) < 0 then return -1 s(of_splitpath(as_path, 2)).Activate try (as_sheet).Select//选择文件中一个工作表(按sheet名称选 择,sheet名称确定的情况下使用) catch( runtimeerror er) //出错的原因可能是工作簿并没有打开,直接返回-1就好了 return -1 end try return 1 end function public function integer of_show (boolean ab_show);//是否显示Excel界面 if of_check() < 0 then return -1 e = ab_show return 1 end function public function integer of_showalldata (string as_path, string as_sheet);//显示所有数据 if of_check(as_path,as_sheet) < 0 then return -1 boolean lb try lb = oks(of_splitpath(as_path, 2)).sheets(as_sheet).AutoFilterMode catch(runtimeerror er) return -1 end try IF lb THEN oks(of_splitpath(as_path, 2)).sheets(as_sheet).ShowAllData //显示所有数 据,关闭自动筛选 oks(of_splitpath(as_path, 2)).sheets(as_sheet).AutoFilterMode = false
x0cEND IF
oks(of_splitpath(as_path, 2)).sheets(as_sheet). = False //取消隐藏,所有行列 oks(of_splitpath(as_path, 2)).sheets(as_sheet). = False //取消隐藏,所有行列 return 1 end function public function integer of_quit ();//退出Excel if of_check() < 0 then return -1 (); return 1 end function public function integer of_sheetdelete (string as_path, string as_sheet);//删除指定sheet, 前提是as已经打开 if of_check(as_path,as_sheet) < 0 then return -1 if of_sheetselect(as_path, as_sheet) < 0 then
return -1 try oks(of_splitpath(as_path, 2)).sheets(as_sheet).Delete//选择文件中一个 工作表(按sheet名称选择,sheet名称确定的情况下使用) catch( runtimeerror er) //出错的原因可能是工作簿并没有打开,直接返回-1就好了 return -1 end try return 1 end function public function long of_get_firstemprow (string as_path, string as_sheet, long al_col[]);//显示所有数据 if of_check(as_path,as_sheet) < 0 then return -1 boolean lb long row,ll_rowcount int i string ls if upperbound(al_col) = 0 then return -1 ll_rowcount = of_rowcount(as_path, as_sheet) for row = ll_rowcount to 1 step -1 ls = '' for i = 1 to upperbound(al_col) ls += of_getvalue(as_path, as_sheet, row, al_col[i]) next if ls = '' then continue end if exit
x0cnext return row end function public function integer of_setvalue (string as_path, integer ai_sheet, long row, string as_col, string as_value);//设置单元格的内容 if of_check() < 0 then return -1 long col col = of_get_num_colid( as_col) return of_setvalue(as_path, ai_sheet, row, col, as_value) end function public function integer of_setvalue (string as_path, string as_sheet, long row, string as_col, string as_value);//设置单元格的内容 if of_check() < 0 then return -1 long col col = of_get_num_colid( as_col) return of_setvalue(as_path, as_sheet, row, col, as_value) end function public function string of_relative_path (string a1, string a2);// //如:在a1中做超链接到a2:a1 = "c:/abc/", a2 = "c:/abc/def/" string ls int i a1 = lower(a1); a2 = lower(a2) if a1 = a2 then return '' //同一个工作簿,返回空值 do while true i = posw(a1, '/') if i <= 0 then else ls = leftw(a1, i) if leftw(a2, lenw(ls)) = ls and leftw(a2, 3) <> '../' then //相同 a1 = midw(a1, i + 1); a2 = midw(a2, i+ 1) else a1 = midw(a1, i + 1);a2 = "../" + a2 end if end if
loop return a2 end function public function integer of_scrollrow (string as_path, string as_sheet, long row);//滚动 到指定的行 if row < 1 or row > of_rowcount( as_path, as_sheet) then return -1
x0cif of_check(as_path,as_sheet) < 0 then return -1 try row = row//workbooks(of_splitpath(as_path, 2)).sheets(as_sheet). catch( runtimeerror er) //出错的原因可能是工作簿并没有打开,直接返回-1就好了 return -1 end try return 1 end function public function integer of_scrollcolumn (string as_path, string as_sheet, long col);// 滚动到指定的列 if col < 1 or col > of_colcount( as_path, as_sheet) then return -1 if of_check(as_path,as_sheet) < 0 then return -1 try column = col catch( runtimeerror er) //出错的原因可能是工作簿并没有打开,直接返回-1就好了 return -1 end try return 1 end function public subroutine of_speed_set (string as_path, string as_sheet, any ast);////设置Excel 的速度性 //constant long xlCalculationAutomatic = -4105 //自动重算 //constant long xlCalculationManual = -4135 //手动重算 //const
ant long xlCalculationSemiautomatic = 2 //除模拟运算表外,自动重算 //st_speed lst //if of_check() < 0 then return lst // = 1 //Updating = Updating //yStatusBar = yStatusBar //Events = Events //ation = ation //ateBeforeSave = ateBeforeSave //yPageBreaks = false //if of_check(as_path, as_sheet) < 0 then return lst ////yPageBreaks = oks(of_splitpath(as_path, 2)).sheets(as_sheet).DisplayPageBreaks //if <> 1 then //ast中并没有写入设置,默认为高速设置 // Updating = TRUE // yStatusBar = false // Events = false // ation = xlCalculationManual // ateBeforeSave = true //// oks(of_splitpath(as_path, 2)).sheets(as_sheet).DisplayPageBreaks = false //else // Updating = Updating
x0c// yStatusBar = yStatusBar // Events = Events // ation = ation // ateBeforeSave = ateBeforeSave //// oks(of_splitpath(as_path, 2)).sheets(as_sheet).DisplayPageBreaks = yPageBreaks //end if //of_save(as_path) //return lst end subroutine on nvo_ call super::create TriggerEvent( this, "constructor" ) end on on nvo_y TriggerEvent( this, "destructor" ) call super::destroy end on event constructor;of_connect() end event event destructor;of_disconnect() end event
x0c


发布评论