uo_xlsmanager.sru 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863
  1. $PBExportHeader$uo_xlsmanager.sru
  2. forward
  3. global type uo_xlsmanager from nonvisualobject
  4. end type
  5. end forward
  6. shared variables
  7. end variables
  8. global type uo_xlsmanager from nonvisualobject
  9. event ue_saveprintersetting ( )
  10. end type
  11. global uo_xlsmanager uo_xlsmanager
  12. type variables
  13. uo_win32api uo_api
  14. uo_xls_constant uo_const
  15. olecontrol ole_con
  16. s_xls_templates s_tem
  17. Boolean AllowEdit = False
  18. Boolean ifclose = False
  19. Boolean enableselect = False
  20. long actionid = 0
  21. s_xls_billlist str_billlist
  22. w_xls ins_w_ole
  23. Private:
  24. oleobject obj_workbook,obj_sheet,obj_cell,obj_xls,obj_flag[],obj_pic,obj_ole
  25. String CurrentDirectory = ''
  26. Long xls_handle
  27. uo_xls_constant uo_constant
  28. end variables
  29. forward prototypes
  30. public subroutine of_reset ()
  31. public subroutine of_set_userpwd (string arg_pwd)
  32. public subroutine of_throwexception (string arg_msg)
  33. private subroutine of_filldata ()
  34. public function boolean of_chksavepath (ref string arg_savepath)
  35. public subroutine of_workbookunlock ()
  36. public subroutine of_workbooklock ()
  37. public subroutine of_showexcel (boolean arg_show)
  38. public subroutine of_setpagebreakpreview ()
  39. public function string of_replacestring (string arg_orgstr, string arg_replacestr, string arg_replacevalue)
  40. public function integer of_sendtoexcel (ref string arg_msg)
  41. public subroutine of_script ()
  42. public subroutine of_activetemplate ()
  43. public subroutine of_set_caption (boolean arg_flag)
  44. public subroutine of_setxlsmax ()
  45. public subroutine of_set_screenupdating (boolean arg_flag)
  46. public subroutine of_setsign (string arg_signname, integer arg_flag, integer arg_type, string arg_billflag, string arg_billname, boolean arg_chk, boolean arg_addchk)
  47. public subroutine of_setexcelwindowsize (integer arg_windowstate)
  48. private function string of_getvalue (string arg_columnname, datastore arg_ds, long arg_row)
  49. end prototypes
  50. event ue_saveprintersetting();//ue_saveprintersetting
  51. if isnull (uo_constant) or isnull(obj_workbook) then return
  52. //save page setting to ini
  53. uo_constant.of_setprofilestring( string(str_billlist.billid)+'-' +trim(str_billlist.templatesname), 'LeftMargin' , string(obj_workbook.ActiveSheet.PageSetup.LeftMargin))
  54. uo_constant.of_setprofilestring( string(str_billlist.billid)+'-' +trim(str_billlist.templatesname), 'RightMargin' , string(obj_workbook.ActiveSheet.PageSetup.RightMargin))
  55. uo_constant.of_setprofilestring( string(str_billlist.billid)+'-' +trim(str_billlist.templatesname), 'TopMargin' , string(obj_workbook.ActiveSheet.PageSetup.TopMargin))
  56. uo_constant.of_setprofilestring( string(str_billlist.billid)+'-' +trim(str_billlist.templatesname), 'BottomMargin' , string(obj_workbook.ActiveSheet.PageSetup.BottomMargin))
  57. uo_constant.of_setprofilestring( string(str_billlist.billid)+'-' +trim(str_billlist.templatesname), 'HeaderMargin' , string(obj_workbook.ActiveSheet.PageSetup.HeaderMargin))
  58. uo_constant.of_setprofilestring( string(str_billlist.billid)+'-' +trim(str_billlist.templatesname), 'FooterMargin' , string(obj_workbook.ActiveSheet.PageSetup.FooterMargin))
  59. uo_constant.of_setprofilestring( string(str_billlist.billid)+'-' +trim(str_billlist.templatesname), 'Orientation' , string(obj_workbook.ActiveSheet.PageSetup.Orientation))
  60. uo_constant.of_setprofilestring( string(str_billlist.billid)+'-' +trim(str_billlist.templatesname), 'PaperSize' , string(obj_workbook.ActiveSheet.PageSetup.PaperSize))
  61. //messagebox('系统提示','保存打印页面设置成功')
  62. end event
  63. public subroutine of_reset ();SetNull(obj_workbook)
  64. SetNull(obj_sheet)
  65. SetNull(obj_cell)
  66. SetNull(obj_xls)
  67. SetNull(ole_con)
  68. //uo_const.create_new_pwd( )
  69. AllowEdit = FALSE
  70. ifclose = FALSE
  71. s_xls_templates s_temnull
  72. s_tem = s_temnull
  73. end subroutine
  74. public subroutine of_set_userpwd (string arg_pwd);uo_const.pwd = arg_pwd
  75. end subroutine
  76. public subroutine of_throwexception (string arg_msg);runtimeerror err
  77. err = Create runtimeerror
  78. err.Text = arg_msg
  79. err.objectname = this.classname( )
  80. THROW err
  81. end subroutine
  82. private subroutine of_filldata ();
  83. TRY
  84. Long i, rowcnt
  85. Long mxrow = 0
  86. Long mxbeginrow = 0
  87. Long ls_i,ll_j,ll_k
  88. Long signcnt = 0
  89. String strvalue,tempstr,Sign,Value
  90. oleobject obj_first
  91. String findsign
  92. findsign = uo_const.sign_begin+'*'+uo_const.sign_end //模糊查找标记
  93. IF IsNull(obj_workbook) THEN
  94. of_throwexception( "没有WorkBook对象")
  95. END IF
  96. obj_sheet = obj_workbook.activesheet //获取当前活动worksheet的引用
  97. FOR ls_i = 1 TO str_billlist.count //循环所有明细表格,查找相应明细标所在的位置
  98. IF str_billlist.bill[ls_i].parentid = 0 THEN CONTINUE
  99. str_billlist.bill[ls_i].mxflag = obj_sheet.Cells.Find(str_billlist.bill[ls_i].billflag) //查找明细标记
  100. IF NOT IsNull(str_billlist.bill[ls_i].mxflag) THEN
  101. mxbeginrow = str_billlist.bill[ls_i].mxflag.row
  102. ELSE
  103. mxbeginrow = 0
  104. END IF
  105. IF mxbeginrow > 0 THEN //根据数据源的行数预先复制明细行到Excel
  106. rowcnt = str_billlist.bill[ls_i].ds_data.RowCount()
  107. Open(w_xls_sys_wait_jdt) //初始化进度条
  108. w_xls_sys_wait_jdt.Show()
  109. w_xls_sys_wait_jdt.wf_accepttol(str_billlist.bill[ls_i].ds_data.RowCount() - 1)
  110. w_xls_sys_wait_jdt.st_msg.Text = "正在初始化模版......"
  111. FOR i = 1 TO rowcnt - 1 //根据明细行数复制明细行
  112. obj_sheet.rows(mxbeginrow).Copy()
  113. obj_sheet.rows(mxbeginrow).Insert(-4121)
  114. w_xls_sys_wait_jdt.wf_inc(i)
  115. NEXT
  116. Close(w_xls_sys_wait_jdt)
  117. END IF
  118. NEXT
  119. signcnt = 0
  120. obj_first = obj_sheet.Cells.Find(findsign)
  121. obj_cell = obj_first
  122. DO WHILE NOT IsNull(obj_cell) //循环查找所有标记,并把所有标记的引用放入数组
  123. signcnt++
  124. obj_flag[signcnt] = obj_cell
  125. obj_cell = obj_sheet.Cells.Find(findsign,obj_cell)
  126. IF IsNull(obj_cell) THEN EXIT
  127. IF obj_cell.Address = obj_first.Address THEN EXIT
  128. LOOP
  129. mxrow = 1
  130. Open(w_xls_sys_wait_jdt) //初始化进度条
  131. w_xls_sys_wait_jdt.Show()
  132. w_xls_sys_wait_jdt.wf_accepttol(signcnt)
  133. w_xls_sys_wait_jdt.st_msg.Text = "正在发送数据..."
  134. s_xls_bill str_bill
  135. FOR ls_i = 1 TO signcnt //循环所有标记引用
  136. obj_cell = obj_flag[ls_i]
  137. strvalue = Trim(obj_cell.Value)
  138. FOR ll_j = 1 TO str_billlist.count //循环查找标记引用里的所有标记,并进行内容替换
  139. str_bill = str_billlist.bill[ll_j]
  140. IF Pos(strvalue, str_bill.billflag) > 0 THEN
  141. strvalue = of_replacestring(strvalue,str_bill.billflag,'')
  142. END IF
  143. IF strvalue = '' OR Pos(strvalue,uo_const.sign_begin) <= 0 OR Pos(strvalue,uo_const.sign_end ) <= 0 THEN EXIT
  144. IF NOT IsValid(str_bill.ds_data ) THEN CONTINUE
  145. IF str_bill.ds_data.RowCount( ) <= 0 THEN CONTINUE
  146. IF str_bill.parentid = 0 THEN
  147. mxrow = 1
  148. ELSE
  149. IF IsNull(str_bill.mxflag ) THEN CONTINUE
  150. mxrow = obj_cell.row - (str_bill.mxflag.row - str_bill.ds_data.RowCount( ) )
  151. // messagebox(string(mxrow),string(str_bill.mxflag.row ))
  152. END IF
  153. IF mxrow <= 0 OR mxrow > str_bill.ds_data.RowCount( ) THEN CONTINUE
  154. FOR ll_k = 1 TO str_bill.count
  155. IF Pos(Lower(strvalue),Lower(Trim(str_bill.column[ll_k].signnameformat))) > 0 THEN
  156. Value = of_getvalue(str_bill.column[ll_k].columnname,str_bill.ds_data,mxrow)
  157. IF str_bill.column[ll_k].columntype = 1 THEN
  158. strvalue = of_replacestring(strvalue,str_bill.column[ll_k].signnameformat,'')
  159. IF FileExists(Value) THEN
  160. decimal pic_width,pic_height
  161. decimal pic_left,pic_top
  162. obj_cell.SELECT
  163. obj_xls.Selection.Activate
  164. //按比例缩放图片
  165. pic_width = obj_xls.Selection.Width
  166. pic_height = obj_xls.Selection.Height
  167. obj_pic = obj_workbook.activesheet.Pictures.Insert(Value)
  168. obj_pic.SELECT
  169. IF obj_xls.Selection.ShapeRange.Height < pic_height AND obj_xls.Selection.ShapeRange.Width < pic_width THEN
  170. pic_height = obj_xls.Selection.ShapeRange.Height
  171. pic_width = obj_xls.Selection.ShapeRange.Width
  172. ELSE
  173. If (obj_xls.Selection.ShapeRange.Width / obj_xls.Selection.ShapeRange.Height) > (pic_width/pic_height) THEN
  174. pic_width = pic_width
  175. pic_height = pic_width / (obj_xls.Selection.ShapeRange.Width / obj_xls.Selection.ShapeRange.Height)
  176. ELSE
  177. pic_width = pic_height * (obj_xls.Selection.ShapeRange.Width / obj_xls.Selection.ShapeRange.Height)
  178. pic_height = pic_height
  179. END IF
  180. END IF
  181. pic_left = (obj_cell.Width - pic_width) / 2
  182. pic_top = (obj_cell.Height - pic_height) / 2
  183. //
  184. obj_xls.Selection.ShapeRange.LockAspectRatio = FALSE
  185. obj_xls.Selection.ShapeRange.Height = pic_height
  186. obj_xls.Selection.ShapeRange.Width = pic_width
  187. obj_pic.Name = str_bill.column[ll_k].signnameformat+'['+String(mxrow)+']'
  188. // obj_pic.Left = pic_left + obj_cell.Left
  189. // obj_pic.Top = pic_top + obj_cell.Top
  190. obj_xls.Selection.ShapeRange.left = pic_left + obj_cell.Left
  191. obj_xls.Selection.ShapeRange.Top = pic_top + obj_cell.Top
  192. END IF
  193. ELSE
  194. strvalue = of_replacestring(strvalue,str_bill.column[ll_k].signnameformat,Value)
  195. END IF
  196. IF strvalue = '' OR Pos(strvalue,uo_const.sign_begin) <= 0 OR Pos(strvalue,uo_const.sign_end ) <= 0 THEN EXIT
  197. END IF
  198. NEXT
  199. NEXT
  200. obj_cell.Value = strvalue
  201. w_xls_sys_wait_jdt.wf_inc(ls_i)
  202. NEXT
  203. Close(w_xls_sys_wait_jdt)
  204. Catch(runtimeerror err)
  205. IF IsValid(w_xls_sys_wait_jdt) THEN Close(w_xls_sys_wait_jdt)
  206. err.Text = '填充数据失败:~n'+err.Text
  207. throw err
  208. END TRY
  209. end subroutine
  210. public function boolean of_chksavepath (ref string arg_savepath);TRY
  211. IF IsNull(arg_savepath) THEN arg_savepath = ''
  212. arg_savepath = Trim(arg_savepath)
  213. IF arg_savepath = '' THEN
  214. This.of_throwexception( '没有输出路径')
  215. END IF
  216. IF Pos(arg_savepath,":") = 0 THEN
  217. arg_savepath = CurrentDirectory +"\"+arg_savepath
  218. END IF
  219. Long Len = 1
  220. DO WHILE Pos(Right(arg_savepath,Len),'\') = 0
  221. Len++
  222. IF Len >= Len(arg_savepath) THEN EXIT
  223. LOOP
  224. Len = Len(arg_savepath)-Len
  225. IF Len <= 0 THEN
  226. This.of_throwexception( '保存Excel文件的路径不正确')
  227. END IF
  228. IF Not Directoryexists(Left(arg_savepath,Len)) THEN
  229. This.of_throwexception( '保存Excel文件的路径不正确')
  230. END IF
  231. IF FileExists(arg_savepath) THEN
  232. IF MessageBox ('系统提示',"目标模版已经存在,是否覆盖?",Question!,YesNo! ) = 2 THEN
  233. This.of_throwexception( '操作被取消')
  234. END IF
  235. IF Not FileDelete(arg_savepath) THEN
  236. This.of_throwexception( '目标文件可能正在使用,不能覆盖')
  237. END IF
  238. END IF
  239. RETURN True
  240. Catch(runtimeerror err)
  241. throw err
  242. RETURN False
  243. END TRY
  244. end function
  245. public subroutine of_workbookunlock ();TRY
  246. obj_workbook.unProtect(uo_const.pwd)
  247. obj_workbook.activesheet.unProtect(uo_const.pwd )
  248. Catch(runtimeerror err)
  249. err.text = '解锁WorkBook失败:~n'+err.text
  250. throw err
  251. END TRY
  252. end subroutine
  253. public subroutine of_workbooklock ();TRY
  254. obj_workbook.Protect(uo_const.pwd,TRUE,false )
  255. obj_workbook.activesheet.Protect(uo_const.pwd,TRUE,TRUE,TRUE )
  256. if not enableselect then obj_workbook.activesheet.EnableSelection = 1
  257. Catch(runtimeerror err)
  258. err.text = '锁定WorkBook失败:~n'+err.text
  259. throw err
  260. END TRY
  261. end subroutine
  262. public subroutine of_showexcel (boolean arg_show);TRY
  263. //obj_xls.Visible = arg_show
  264. Catch(runtimeerror err)
  265. err.text = '隐藏Excel进程失败:~n'+err.text
  266. throw err
  267. END TRY
  268. end subroutine
  269. public subroutine of_setpagebreakpreview ();//String
  270. TRY
  271. // if of_connecttoexcel(arg_msg) <> 1 then
  272. // return 0
  273. // end if
  274. // obj_xls.visible = false
  275. IF Not obj_xls.isalive( ) THEN
  276. This.of_throwexception( '连接Excel失败')
  277. END IF
  278. obj_xls.Application.WindowState = -4137
  279. obj_xls.ActiveWindow.WindowState = -4137
  280. obj_xls.ActiveWindow.View = 2
  281. obj_xls.ActiveWindow.Zoom = 100
  282. obj_xls.Application.displayalerts = False
  283. Catch(runtimeerror err)
  284. err.Text = '设置浏览模式失败:~n'+err.Text
  285. throw err
  286. END TRY
  287. end subroutine
  288. public function string of_replacestring (string arg_orgstr, string arg_replacestr, string arg_replacevalue);Long i
  289. if isnull(arg_orgstr) then arg_orgstr = ''
  290. if isnull(arg_replacestr) then arg_replacestr = ''
  291. if isnull(arg_replacevalue) then arg_replacevalue = ''
  292. if arg_orgstr = '' then return arg_orgSTR
  293. if arg_replacestr = '' then return arg_orgSTR
  294. i = Pos(arg_orgSTR,arg_replacestr)
  295. DO WHILE i > 0
  296. arg_orgSTR = Replace(arg_orgSTR,i,Len(arg_replacestr),arg_replacevalue)
  297. i = Pos(arg_orgSTR,arg_replacestr)
  298. LOOP
  299. RETURN arg_orgSTR
  300. end function
  301. public function integer of_sendtoexcel (ref string arg_msg);Long rslt = 1
  302. TRY
  303. String savepath = '',Filename = ''
  304. Long li_rc
  305. IF actionid = 3 Or actionid = 5 THEN
  306. li_rc = GetFileSaveName ( "保存文件", savepath, Filename, "Excel", "Excel Files(*.xls),*.xls,Excel 模版(*.xlt),*.xlt")
  307. IF li_rc <> 1 THEN
  308. RETURN 1
  309. END IF
  310. END IF
  311. of_activetemplate() //激活Excel
  312. of_showexcel(False) //隐藏窗口
  313. of_set_ScreenUpdating(False) //暂停更新界面
  314. of_set_caption(False) //隐藏窗口标题栏的删除按钮
  315. IF actionid <> 4 And actionid <> 5 THEN
  316. of_filldata() //填充数据
  317. END IF
  318. // IF of_setpagebreakpreview(arg_msg) <> 1 THEN RETURN 0 //设置浏览模式为页面预览
  319. IF Not AllowEdit THEN //锁定workbook
  320. of_workbooklock()
  321. END IF
  322. //get page setting from ini
  323. //messagebox('','get page setting from ini' )
  324. try
  325. obj_workbook.ActiveSheet.PageSetup.LeftMargin = integer(uo_constant.of_profilestring( string(str_billlist.billid)+'-' + trim(str_billlist.templatesname), 'LeftMargin', string(obj_workbook.ActiveSheet.PageSetup.LeftMargin)))
  326. obj_workbook.ActiveSheet.PageSetup.RightMargin = integer(uo_constant.of_profilestring( string(str_billlist.billid)+'-' + trim(str_billlist.templatesname), 'RightMargin', string(obj_workbook.ActiveSheet.PageSetup.RightMargin)))
  327. obj_workbook.ActiveSheet.PageSetup.TopMargin = integer(uo_constant.of_profilestring( string(str_billlist.billid)+'-' + trim(str_billlist.templatesname), 'TopMargin', string(obj_workbook.ActiveSheet.PageSetup.TopMargin)))
  328. obj_workbook.ActiveSheet.PageSetup.BottomMargin = integer(uo_constant.of_profilestring( string(str_billlist.billid)+'-' + trim(str_billlist.templatesname), 'BottomMargin', string(obj_workbook.ActiveSheet.PageSetup.BottomMargin)))
  329. obj_workbook.ActiveSheet.PageSetup.HeaderMargin = integer(uo_constant.of_profilestring( string(str_billlist.billid)+'-' + trim(str_billlist.templatesname), 'HeaderMargin', string(obj_workbook.ActiveSheet.PageSetup.HeaderMargin)))
  330. obj_workbook.ActiveSheet.PageSetup.FooterMargin = integer(uo_constant.of_profilestring( string(str_billlist.billid)+'-' + trim(str_billlist.templatesname), 'FooterMargin', string(obj_workbook.ActiveSheet.PageSetup.FooterMargin)))
  331. obj_workbook.ActiveSheet.PageSetup.Orientation = integer(uo_constant.of_profilestring( string(str_billlist.billid)+'-' + trim(str_billlist.templatesname), 'Orientation', string(obj_workbook.ActiveSheet.PageSetup.Orientation)))
  332. if integer(uo_constant.of_profilestring( string(str_billlist.billid)+'-' + trim(str_billlist.templatesname), 'PaperSize',string(obj_workbook.ActiveSheet.PageSetup.PaperSize))) <> 256 then
  333. obj_workbook.ActiveSheet.PageSetup.PaperSize = integer(uo_constant.of_profilestring( string(str_billlist.billid)+'-' + trim(str_billlist.templatesname), 'PaperSize',string(obj_workbook.ActiveSheet.PageSetup.PaperSize))) //
  334. end if
  335. Catch(runtimeerror er)
  336. //throw er
  337. end try
  338. of_set_ScreenUpdating(True) //更新屏幕
  339. of_showexcel(True)
  340. CHOOSE CASE actionid
  341. CASE 0 //发送数据
  342. ifclose = False
  343. //保存设置的窗口
  344. if isvalid( this.ins_w_ole ) then
  345. this.ins_w_ole.ins_obj =this
  346. this.ins_w_ole.show()
  347. end if
  348. CASE 1 //打印预览
  349. ifclose = True
  350. obj_workbook.printpreview
  351. CASE 2 //直接打印
  352. ifclose = True
  353. //打印设置
  354. // obj_workbook.activesheet.pagesetup.PrintTitleRows = ""
  355. // obj_workbook.activesheet.pagesetup.PrintTitleColumns = ""
  356. // obj_workbook.ActiveSheet.PageSetup.PrintArea = ""
  357. // obj_workbook.ActiveSheet.PageSetup.LeftHeader = ""
  358. // obj_workbook.ActiveSheet.PageSetup.CenterHeader = ""
  359. // obj_workbook.ActiveSheet.PageSetup.RightHeader = ""
  360. // obj_workbook.ActiveSheet.PageSetup.LeftFooter = ""
  361. // obj_workbook.ActiveSheet.PageSetup.CenterFooter = ""
  362. // obj_workbook.ActiveSheet.PageSetup.RightFooter = ""
  363. // obj_workbook.ActiveSheet.PageSetup.LeftMargin = obj_workbook.Application.InchesToPoints(0.748031496062992)
  364. // obj_workbook.ActiveSheet.PageSetup.RightMargin = obj_workbook.Application.InchesToPoints(0.748031496062992)
  365. // obj_workbook.ActiveSheet.PageSetup.TopMargin = obj_workbook.Application.InchesToPoints(0.984251968503937)
  366. // obj_workbook.ActiveSheet.PageSetup.BottomMargin = obj_workbook.Application.InchesToPoints(0.984251968503937)
  367. // obj_workbook.ActiveSheet.PageSetup.HeaderMargin = obj_workbook.Application.InchesToPoints(0.511811023622047)
  368. // obj_workbook.ActiveSheet.PageSetup.FooterMargin = obj_workbook.Application.InchesToPoints(0.511811023622047)
  369. // obj_workbook.ActiveSheet.PageSetup.Orientation = 1
  370. // obj_workbook.ActiveSheet.PageSetup.PaperSize = 9
  371. // obj_workbook.ActiveSheet.PageSetup.PrintHeadings = False
  372. // obj_workbook.ActiveSheet.PageSetup.PrintGridlines = False
  373. // obj_workbook.ActiveSheet.PageSetup.PrintComments = -4142
  374. // obj_workbook.ActiveSheet.PageSetup.PrintQuality = 600
  375. // obj_workbook.ActiveSheet.PageSetup.CenterHorizontally = False
  376. // obj_workbook.ActiveSheet.PageSetup.CenterVertically = False
  377. // obj_workbook.ActiveSheet.PageSetup.Draft = False
  378. // obj_workbook.ActiveSheet.PageSetup.FirstPageNumber = xlAutomatic
  379. // obj_workbook.ActiveSheet.PageSetup.Order = 1
  380. // obj_workbook.ActiveSheet.PageSetup.BlackAndWhite = False
  381. // obj_workbook.ActiveSheet.PageSetup.Zoom = 100
  382. // obj_workbook.ActiveSheet.PageSetup.PrintErrors = 0
  383. obj_workbook.activesheet.printout()
  384. CASE 3 //发送数据并保存
  385. ifclose = True
  386. of_set_ScreenUpdating(False) //暂停更新界面
  387. of_chksavepath(savepath)
  388. obj_workbook.SaveAs(savepath)
  389. of_set_ScreenUpdating(True) //更新界面
  390. CASE 4 //浏览模板
  391. ifclose = False
  392. CASE 5 //保存模板
  393. ifclose = True
  394. of_set_ScreenUpdating(False) //暂停更新界面
  395. of_chksavepath(savepath)
  396. obj_workbook.SaveAs(savepath)
  397. of_set_ScreenUpdating(True) //更新界面
  398. END CHOOSE
  399. uo_api.u_setwindowpos( xls_handle)
  400. IF Not IsNull(ole_con) And ifclose THEN //自动关闭窗口
  401. obj_workbook.Close()
  402. END IF
  403. if isvalid( this.ins_w_ole ) then this.ins_w_ole.wf_setwinpos()
  404. Catch(runtimeerror err)
  405. IF IsValid(obj_workbook) THEN
  406. obj_workbook.Close()
  407. END IF
  408. arg_msg = err.Text
  409. rslt = 0
  410. END TRY
  411. RETURN rslt
  412. end function
  413. public subroutine of_script ();//保存图片
  414. //用Clipboard
  415. //
  416. //Dim Picture As StdPicture
  417. //...
  418. //Selection.Copy
  419. //Picture = Clipboard.GetData()
  420. //SavePicture Picture, "c:\myPic.bmp"
  421. //...
  422. //
  423. //Excel VBA cell的一些属性和toolsbar
  424. //ken_kang 发表于 2007-7-5 16:25:00
  425. // sht.Cells(1, i).Interior.ColorIndex = 15 ‘cell的颜色
  426. // sht.Cells(1, i).VerticalAlignment = 1'cell内向上还是向下靠齐
  427. // sht.Cells(1, i).WrapText = True’cell内的文字是否自动回行
  428. // sht.Cells(1, i).Borders. = "1"‘表格的边界,1正常的那种
  429. // sht.Cells(1, i).Borders.Weight = "3"’表格的粗细
  430. //
  431. //
  432. //sht.row(1).insert 在第一行的上面插入一行。
  433. //
  434. //
  435. //sht.Rows("7:7").Select '选定EXCEL表的第7行
  436. //sht.Selection.Delete shift:=xlUp '删除选定的行
  437. //
  438. //
  439. //实施打印的语句:
  440. //
  441. //
  442. //ActiveSelectedSheets.PrintOut copies:=TextBox1.Text ‘根据打印份数输出到打印机
  443. //
  444. //Toolsbar
  445. //
  446. //
  447. // Set ourToolBar = CommandBars.Add(Name:="mybar", Position:=msoBarTop)
  448. // ourToolBar.Visible = True
  449. // ourToolBar.Enabled = True
  450. // ourToolBar.Controls.Add Type:=msoControlButton
  451. // With ourToolBar.Controls(1)
  452. // .Width = 60
  453. //' .Style = msoButtonIcon
  454. // .OnAction = "Start"
  455. // .TooltipText = "Pls open the xls file and click Start"
  456. // .Caption = "Process the format of s"
  457. // .FaceId = 111
  458. // .Visible = True
  459. // End With
  460. //
  461. //
  462. end subroutine
  463. public subroutine of_activetemplate (); try
  464. ole_con.Activate( OffSite!) //激活excel
  465. obj_workbook = ole_con.Object //Workbook对象的引用
  466. obj_xls = obj_workbook.Application
  467. obj_xls.DisplayAlerts = False //不显示特定的警告和消息
  468. xls_handle = obj_xls.Hwnd //窗口句柄
  469. catch(runtimeerror err)
  470. err.text ='激活Excel失败~n'+err.text
  471. end try
  472. end subroutine
  473. public subroutine of_set_caption (boolean arg_flag);TRY
  474. return
  475. Long lWnd
  476. lWnd = uo_api.GetWindowLong(xls_handle, uo_api.GWL_STYLE)
  477. IF arg_flag THEN
  478. lWnd += uo_api.WS_CAPTION
  479. ELSE
  480. lWnd -= uo_api.WS_CAPTION
  481. END IF
  482. uo_api.SetWindowLong(xls_handle,uo_api.GWL_STYLE,lWnd )
  483. Catch(runtimeerror err)
  484. err.text = '隐藏窗口标题栏失败:~n'+err.text
  485. throw err
  486. END TRY
  487. end subroutine
  488. public subroutine of_setxlsmax ();
  489. //String
  490. TRY
  491. obj_xls.Application.WindowState = -4137
  492. obj_xls.ActiveWindow.WindowState = -4137
  493. obj_xls.ActiveWindow.View = 1
  494. obj_xls.ActiveWindow.Zoom = 100
  495. Catch(runtimeerror err)
  496. err.text = '最大化Excel失败~n'+err.text
  497. throw err
  498. END TRY
  499. end subroutine
  500. public subroutine of_set_screenupdating (boolean arg_flag);//String
  501. TRY
  502. // if of_connecttoexcel() <> 1 then
  503. // return 0
  504. // end if
  505. obj_xls.Application.ScreenUpdating = arg_flag
  506. Catch(runtimeerror err)
  507. err.text = '关闭屏幕更新失败:~n'+err.text
  508. throw err
  509. END TRY
  510. end subroutine
  511. public subroutine of_setsign (string arg_signname, integer arg_flag, integer arg_type, string arg_billflag, string arg_billname, boolean arg_chk, boolean arg_addchk);
  512. TRY
  513. String arg_msg,Value
  514. oleobject obj_mxcell
  515. obj_cell = obj_xls.ActiveCell
  516. obj_sheet = obj_workbook.activesheet
  517. IF IsNull(obj_cell) THEN
  518. This.of_throwexception( '请选定要填充标记的单元格')
  519. END IF
  520. String ls_msg = ''
  521. IF arg_chk THEN
  522. IF arg_addchk THEN
  523. ls_msg = '是否确定要把标记"'+arg_signname+'"追加到单元格('+String(obj_cell.Address() )+')'
  524. ELSE
  525. ls_msg = '是否确定要把标记"'+arg_signname+'"覆盖到单元格('+String(obj_cell.Address() )+')'
  526. END IF
  527. IF MessageBox ('系统提示',ls_msg,Question!,YesNo! ) = 2 THEN
  528. RETURN
  529. END IF
  530. END IF
  531. IF arg_flag = 0 THEN
  532. IF IsNull(obj_cell.Value) THEN
  533. obj_cell.Value = arg_signname
  534. ELSE
  535. Value = Trim(String(obj_cell.Value))
  536. IF arg_addchk THEN
  537. IF Pos(Value, arg_signname) > 0 THEN
  538. This.of_throwexception( '请不要在同一单元格里追加重复标记')
  539. END IF
  540. obj_cell.Value = Value + arg_signname
  541. ELSE
  542. obj_cell.Value = arg_signname
  543. END IF
  544. END IF
  545. ELSEIF arg_flag = 1 THEN
  546. obj_mxcell = obj_sheet.Cells.Find(arg_billflag)
  547. // messagebox(arg_signname,arg_billflag)
  548. IF arg_signname = arg_billflag THEN
  549. IF Not IsNull(obj_mxcell) THEN
  550. This.of_throwexception('模版中已经存在明细表'+arg_billname+'的标记,请不要重复添加!')
  551. ELSE
  552. IF Not IsNull(obj_cell.Value ) THEN
  553. IF MessageBox ('系统提示','是否确定要清空单元格('+String(obj_cell.Address() )+')的内容以填充明细表'+arg_billname+'的标记',Question!,YesNo! ) = 2 THEN
  554. RETURN
  555. END IF
  556. END IF
  557. obj_cell.Value = arg_signname
  558. obj_mxcell = obj_cell
  559. END IF
  560. ELSE
  561. IF IsNull(obj_mxcell) THEN
  562. This.of_throwexception('要添加明细表'+arg_billname+'的项,请先添加明细标记!')
  563. END IF
  564. IF obj_mxcell.row <> obj_cell.row THEN
  565. This.of_throwexception('明细项必须添加到明细标记'+arg_billname+'所在行!')
  566. END IF
  567. IF obj_mxcell.column <= obj_cell.column THEN
  568. String str
  569. Long cnt = 1
  570. cnt = 1
  571. IF IsNull(obj_sheet.Cells(obj_mxcell.row,obj_cell.column +cnt ).Value) THEN
  572. str = ''
  573. ELSE
  574. str = Trim(obj_sheet.Cells(obj_mxcell.row,obj_cell.column +cnt ).Value)
  575. END IF
  576. DO WHILE str <> ''
  577. cnt ++
  578. IF cnt > 1000 THEN
  579. This.of_throwexception('系统出现异常,移动明细标记失败,请重试!')
  580. END IF
  581. IF IsNull(obj_sheet.Cells(obj_mxcell.row,obj_cell.column +cnt ).Value) THEN
  582. str = ''
  583. ELSE
  584. str = Trim(obj_sheet.Cells(obj_mxcell.row,obj_cell.column +cnt ).Value)
  585. END IF
  586. LOOP
  587. obj_sheet.Cells(obj_mxcell.row,obj_cell.column +cnt ).Value = obj_mxcell.Value
  588. obj_mxcell.Value = ''
  589. END IF
  590. IF IsNull(obj_cell.Value) THEN
  591. obj_cell.Value = arg_signname
  592. ELSE
  593. Value = String(obj_cell.Value)
  594. IF arg_addchk And Pos(Value, arg_signname) > 0 THEN
  595. This.of_throwexception('请不要在同一单元格里插入重复标记!')
  596. END IF
  597. IF arg_addchk THEN
  598. obj_cell.Value = Value + arg_signname
  599. ELSE
  600. obj_cell.Value = arg_signname
  601. END IF
  602. END IF
  603. END IF
  604. END IF
  605. Catch(runtimeerror err)
  606. throw err
  607. return
  608. END TRY
  609. end subroutine
  610. public subroutine of_setexcelwindowsize (integer arg_windowstate);TRY
  611. IF arg_WindowState = 0 THEN
  612. IF Not IsNull(obj_xls) THEN
  613. IF obj_xls.isalive( ) THEN
  614. //obj_xls.ActiveWindow.WindowState = -4137
  615. obj_xls.Application.WindowState = -4140
  616. END IF
  617. END IF
  618. ELSE
  619. IF Not IsNull(obj_xls) THEN
  620. IF obj_xls.isalive( ) THEN
  621. //obj_xls.ActiveWindow.WindowState = -4137
  622. IF obj_xls.Application.WindowState = -4140 THEN
  623. obj_xls.Application.WindowState = -4143
  624. END IF
  625. END IF
  626. END IF
  627. END IF
  628. Catch(runtimeerror err)
  629. throw err
  630. END TRY
  631. end subroutine
  632. private function string of_getvalue (string arg_columnname, datastore arg_ds, long arg_row);String result = ''
  633. result = arg_ds.Describe("Evaluate('Lookupdisplay("+arg_columnname+")'," + String (arg_row) + ")")
  634. IF IsNull(result) THEN result = ''
  635. result = trim(result)
  636. RETURN result
  637. end function
  638. on uo_xlsmanager.create
  639. call super::create
  640. TriggerEvent( this, "constructor" )
  641. end on
  642. on uo_xlsmanager.destroy
  643. TriggerEvent( this, "destructor" )
  644. call super::destroy
  645. end on
  646. event constructor; uo_api = create uo_win32api
  647. uo_constant =create uo_xls_constant
  648. //if use_userpwd then uo_const.pwd = userpwd
  649. CurrentDirectory = uo_api.u_getcurrentdirectory( )
  650. of_reset()
  651. end event
  652. event destructor;IF IsValid(w_xls_sys_wait_jdt) THEN Close(w_xls_sys_wait_jdt)
  653. String arg_msg
  654. TRY
  655. of_set_caption(True)
  656. //obj_workbook.Close()
  657. //obj_xls.Close()
  658. uo_api.SetWindowPos(xls_handle,1,0,0,0,0,3)
  659. Catch(runtimeerror err)
  660. END TRY
  661. end event