n_cst_dw2excel.sru 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. $PBExportHeader$n_cst_dw2excel.sru
  2. forward
  3. global type n_cst_dw2excel from nonvisualobject
  4. end type
  5. end forward
  6. global type n_cst_dw2excel from nonvisualobject autoinstantiate
  7. event ue_process_export ( )
  8. end type
  9. type prototypes
  10. FUNCTION ulong LoadLibraryExW( string lpLibFileName ,ulong hFiles, ulong dwFlags) LIBRARY "kernel32.dll"
  11. FUNCTION ulong LoadLibraryA( string lpLibFileName) LIBRARY "kernel32.dll" ALIAS FOR "LoadLibraryA"
  12. FUNCTION ulong LoadLibraryW( string lpLibFileName) LIBRARY "kernel32.dll" ALIAS FOR "LoadLibraryW"
  13. FUNCTION ulong FreeLibrary(ulong hLibModule) LIBRARY "kernel32.dll"
  14. end prototypes
  15. type variables
  16. Private:
  17. String is_FileName
  18. Boolean ib_OpenExcelFile =False //在导出完成之后,是否提示用户打开Excel文件
  19. Boolean ib_ShowZeroValues =TRUE // 在Excel文件中,单元的数据为0时,是否显示数据内容
  20. Boolean ib_WriteBKColor =TRUE //是否输出背景颜色
  21. Boolean ib_FreezeTitles=TRUE //是否冻结报表表头
  22. Boolean ib_ShowGridLines=False //是否显示表格线
  23. Boolean ib_ProcessSparse =TRUE //是否处理数据窗口的Spare属性
  24. PowerObject ipos[]
  25. String is_SheetNames[]
  26. String is_Language // EN 英文 CN 中文简体 BIG5 繁体中文
  27. String is_DefFontName //设置工作薄的缺省字体名称 ,如果没有设置,则根据当前操作系统自动设置 宋体(简体) 細明體(繁体 ) Arial(其它操作系统)
  28. uInt ii_DefFontSize //设置工作薄的缺省字体大小 ,如果没有设置,则缺省为 9 号字体
  29. //License信息最好通过OF_SetLicense函数设置
  30. //这样可以避免DW2XLS升级时,需要再次修改这两个变量的值
  31. String CompanyName="佛山市顺德区龙嘉软件有限公司" //注册的单位名称
  32. String LICENSECODE ="8BF262AEBC8D331FAFED0D659E26284E48E8E31FC12597D54134E4D9170F2F46" //在此处更新DW2XLS的授权注册码,
  33. n_dw2xls_progress inv_Progress
  34. n_dw2xls_Resource inv_Res
  35. end variables
  36. forward prototypes
  37. public function integer of_dw2excel (powerobject apo, string as_filename)
  38. public function integer of_dw2excel (readonly powerobject apos[], readonly string as_filename)
  39. public function integer of_dw2excel (readonly powerobject apo, readonly string as_filename, string as_sheetname)
  40. public function integer of_dw2excel (readonly powerobject apos[], readonly string as_sheetnames[], readonly string as_filename)
  41. public subroutine of_setshowprogress (boolean ab_show)
  42. public subroutine of_setopenexcelfile (boolean ab_open)
  43. public function Boolean of_checkexcelapplicaiton ()
  44. public function boolean of_checkfilename (string as_filename)
  45. public function Boolean of_checksheetname (string as_name)
  46. public function string of_getcompanyname ()
  47. public function integer of_report2excel (ref datawindow adw, readonly string as_filename)
  48. public function long of_parsetoarray (string as_source, string as_delimiter, ref string as_array[])
  49. public subroutine of_setlicense (readonly string as_companyname, readonly string as_licensecode)
  50. public subroutine of_setlanguage (readonly string as_language, readonly string as_deffontname)
  51. public function Boolean of_openexcelfile (readonly string as_filename)
  52. public subroutine of_setshowzerovalues (readonly boolean ab_show)
  53. public subroutine of_setwritebkcolor (readonly boolean ab_flag)
  54. public subroutine of_setfreezetitles (readonly boolean ab_flag)
  55. public subroutine of_setshowgridlines (readonly boolean ab_show)
  56. public subroutine of_setprocesssparse (readonly boolean ab_flag)
  57. public subroutine of_setfontsize (readonly unsignedinteger ai_fontsize)
  58. public function string of_gettitle ()
  59. end prototypes
  60. event ue_process_export();Long li, lj, li_Sheets, li_Index
  61. Long li_Progress_Data,li_Progress_Picture, li_Step
  62. ulong li_hWorkBook, li_hSheet
  63. oleobject ole_excel, ole_sheet
  64. n_dw2xls_Requestor lnv_Requestor[]
  65. n_dw2xls_WinApi lnv_Api
  66. SetPointer(HourGlass!)
  67. li_Sheets = UpperBound(ipos)
  68. TRY
  69. lnv_Api = Create n_dw2xls_WinApi
  70. lnv_Api.OF_LoadWriter()
  71. //设置授权信息
  72. IF COMPANYNAME<>"" AND LICENSECODE<>"" Then
  73. lnv_Api.SetLicense(COMPANYNAME, LICENSECODE )
  74. END IF
  75. lnv_Api.SetProgress( Handle(inv_Progress.iw_progress))
  76. //设置工作的缺省字体 ,如果没有设置,则根据当前操作系统自动设置 宋体(简体) 細明體(繁体 ) Arial(其它操作系统)
  77. //必须在调用AddWorkSheet之前进行调用
  78. IF is_DefFontName<>'' Then
  79. lnv_Api.SetDefFontName(is_DefFontName)
  80. END IF
  81. IF ii_DefFontSize>0 Then
  82. lnv_Api.SetDefFontSize(ii_DefFontSize)
  83. END IF
  84. li_hWorkBook =lnv_Api.AddWorkBook()
  85. For li =1 To li_Sheets
  86. lnv_Requestor[li] =Create n_dw2xls_Requestor
  87. lnv_Requestor[li].OF_SetWinApi(lnv_Api)
  88. IF lnv_Requestor[li].OF_SetRequestor(ipos[li],inv_Progress ) <>1 Then
  89. Continue
  90. END IF
  91. lnv_Requestor[li].OF_GetLayout().OF_Get_ProgressTotal(li_Progress_Data, li_Progress_Picture)
  92. Next
  93. inv_Progress.OF_StepIt()
  94. li_Step =2 //保留的进度百分比
  95. IF li_Progress_Picture>0 Then
  96. ole_excel = create oleobject
  97. li_Index = ole_excel.ConnectToNewObject('Excel.Application')
  98. IF li_Index <> 0 then
  99. destroy ole_excel
  100. ELSE
  101. inv_Progress.OF_StepIt()
  102. inv_Progress.ib_WritePictures =TRUE
  103. END IF
  104. li_Step +=4
  105. ELSE
  106. li_Step +=1
  107. END IF
  108. inv_Progress.OF_Intial_Progress(li_Progress_Data +li_Progress_Picture *3 ,li_Step)
  109. li_Index =0
  110. For li =1 To li_Sheets
  111. IF inv_Progress.ib_Cancel Then
  112. Exit
  113. END IF
  114. IF Not IsValid(lnv_Requestor[li].OF_GetLayout()) Then
  115. Continue
  116. END IF
  117. li_hSheet =lnv_Api.AddWorkSheet(li_hWorkBook, is_sheetnames[li] )
  118. lnv_Api.SetShowZeroValues(li_hSheet,ib_ShowZeroValues)
  119. lnv_Api.SetShowGridLines(li_hSheet, ib_ShowGridLines)
  120. lnv_Requestor[li].OF_Output(li_hSheet, 0)
  121. li_Index++
  122. lnv_Requestor[li].OF_GetLayout().ii_SheetIndex =li_Index
  123. Next
  124. IF inv_Progress.ib_Cancel Then
  125. inv_Progress.OF_Close_Progress()
  126. ELSE
  127. inv_Progress.OF_DisableCancel() //数据生成完毕后,禁止取消
  128. lnv_Api.SaveWorkBook(li_hWorkBook, is_FileName)
  129. lnv_Api.DestroyWorkBook(li_hWorkBook)
  130. li_hWorkBook =0
  131. //再次检查是否需要输出图片或图表
  132. inv_Progress.ib_WritePictures=False
  133. For li =1 To li_Sheets
  134. IF Not IsValid(lnv_Requestor[li].OF_GetLayout()) Then
  135. Continue
  136. END IF
  137. IF lnv_Requestor[li].OF_GetLayout().OF_CheckWritePictures() Then
  138. inv_Progress.ib_WritePictures=TRUE
  139. Exit
  140. END IF
  141. Next
  142. //输出图片,当前版本采用Ole方式输出,所以速度较慢
  143. IF inv_Progress.ib_WritePictures Then
  144. ole_excel.Application.Workbooks.Open(is_FileName)
  145. inv_Progress.OF_StepIt()
  146. For li =1 To li_Sheets
  147. IF Not IsValid(lnv_Requestor[li].OF_GetLayout()) Then
  148. Continue
  149. END IF
  150. IF lnv_Requestor[li].OF_GetLayout().OF_CheckWritePictures() Then
  151. li_Index = lnv_Requestor[li].OF_GetLayout().ii_SheetIndex
  152. ole_sheet= ole_Excel.application.activeworkbook.WorkSheets.Item[li_Index]
  153. lnv_Requestor[li].OF_GetLayout().of_WritePictures(ole_excel, ole_sheet,inv_Progress)
  154. END IF
  155. Next
  156. ole_excel.application.ActiveSheet.Cells(1,1).Select()
  157. ole_excel.application.ActiveSheet.Cells(1,1).Activate()
  158. ole_excel.application.activeworkbook.save()
  159. inv_Progress.OF_StepIt()
  160. IF ib_OpenExcelFile Then
  161. IF MessageBox(inv_Res.Tips, inv_Res.OF_Format( inv_Res.OpenFileConfirm, is_FileName),Question!,YesNo!)=2 Then
  162. ib_OpenExcelFile =False
  163. END IF
  164. END IF
  165. IF ib_OpenExcelFile Then
  166. ole_excel.application.ActiveWindow.WindowState= -4137 //最大化窗口
  167. ole_excel.application.Visible = True
  168. ole_excel.DisConnectObject()
  169. ELSE
  170. ole_excel.application.Workbooks.close()
  171. ole_excel.application.Quit()
  172. ole_excel.DisConnectObject()
  173. Destroy ole_excel
  174. END IF
  175. ELSE
  176. IF ib_OpenExcelFile Then
  177. IF MessageBox(inv_Res.Tips, inv_Res.OF_Format( inv_Res.OpenFileConfirm, is_FileName),Question!,YesNo!)=1 Then
  178. OF_OpenExcelFile(is_FileName)
  179. END IF
  180. END IF
  181. END IF
  182. inv_Progress.ii_Result =1
  183. END IF
  184. //编译为DLL, 不支持处理 OleRuntimeError 异常
  185. Catch(OleRuntimeError ex1)
  186. MessageBox("DW2XLS Error",ex1.getMessage(),StopSign!)
  187. inv_Progress.ii_Result = -1
  188. Catch(RuntimeError ex3)
  189. MessageBox("DW2XLS Error ",ex3.getMessage(),StopSign!)
  190. inv_Progress.ii_Result = -1
  191. END TRY
  192. IF li_hWorkBook>0 Then
  193. lnv_Api.DestroyWorkBook(li_hWorkBook)
  194. li_hWorkBook =0
  195. END IF
  196. IF IsValid(ole_excel) AND inv_Progress.ii_Result =-1 Then
  197. IF IsValid(ole_excel.application.activeworkbook ) Then
  198. ole_excel.application.activeworkbook.save()
  199. END IF
  200. ole_excel.application.Workbooks.close()
  201. ole_excel.application.Quit()
  202. ole_excel.DisConnectObject()
  203. Destroy ole_excel
  204. END IF
  205. For li=1 To li_Sheets
  206. Destroy lnv_Requestor[li]
  207. Next
  208. lnv_Api.OF_ReloadWriter()
  209. Destroy lnv_Api
  210. inv_Progress.OF_Close_Progress()
  211. SetPointer(Arrow!)
  212. end event
  213. public function integer of_dw2excel (powerobject apo, string as_filename);Return OF_dw2Excel(apo,as_FileName,"Sheet1")
  214. end function
  215. public function integer of_dw2excel (readonly powerobject apos[], readonly string as_filename);Int li
  216. String ls_Sheets[]
  217. For li=1 To UpperBound(apos)
  218. ls_Sheets[li]="Sheet"+String(li)
  219. Next
  220. Return OF_DW2Excel(apos, ls_Sheets, as_FileName)
  221. end function
  222. public function integer of_dw2excel (readonly powerobject apo, readonly string as_filename, string as_sheetname);PowerObject lpos[]
  223. String ls_SheetNames[]
  224. lpos[1] = apo
  225. ls_SheetNames[1] =as_SheetName
  226. Return OF_DW2Excel(lpos, ls_SheetNames, as_FileName)
  227. end function
  228. public function integer of_dw2excel (readonly powerobject apos[], readonly string as_sheetnames[], readonly string as_filename);Long li, lj, li_Sheets,li_Result
  229. //IF Handle(GetApplication())<>0 Then
  230. // MessageBox("提示","DW2XLS DEMO 程序只能在PB开发环境中运行!",StopSign!)
  231. // Return -1
  232. //END IF
  233. li_Sheets = UpperBound(apos)
  234. IF li_Sheets<>UpperBound(as_sheetnames) Then
  235. Return -1
  236. END IF
  237. For li =1 To li_Sheets
  238. IF Not IsValid(apos[li]) Then RETURN -1
  239. IF TypeOF(apos[li])<>DataWindow! AND &
  240. TypeOF(apos[li])<>Datastore! AND &
  241. TypeOF(apos[li])<>DataWindowChild! Then
  242. Return -1
  243. END IF
  244. Next
  245. //工作表不能有相同的名称
  246. For li=1 To li_Sheets
  247. IF Trim(as_sheetnames[li] ) ="" Then Return -1
  248. IF Not OF_CheckSheetName(as_sheetnames[li]) Then Return -1 //工作表名称不符号Excel 的要求
  249. For lj=li+1 To li_Sheets
  250. IF as_sheetnames[li] = as_sheetnames[lj] Then
  251. Return -1
  252. END IF
  253. Next
  254. Next
  255. IF Not OF_CheckFileName(as_FileName) Then
  256. Return -1
  257. END IF
  258. ipos=apos
  259. is_SheetNames =as_SheetNames
  260. is_FileName = as_FileName
  261. SetPointer(HourGlass!)
  262. inv_Progress =Create n_dw2xls_Progress
  263. inv_Progress.OF_SetRequestor(This ,inv_Res )
  264. inv_Progress.ib_WriteBKColor = ib_WriteBKColor
  265. inv_Progress.ib_FreezeTitles = ib_FreezeTitles
  266. inv_Progress.ib_ProcessSparse = ib_ProcessSparse
  267. inv_Progress.OF_Open_Progress()
  268. li_Result = inv_Progress.ii_Result
  269. Destroy inv_Res
  270. Destroy inv_Progress
  271. Return li_Result
  272. end function
  273. public subroutine of_setshowprogress (boolean ab_show);//ib_ShowProgress = ab_show
  274. end subroutine
  275. public subroutine of_setopenexcelfile (boolean ab_open);ib_OpenExcelFile = ab_Open
  276. end subroutine
  277. public function Boolean of_checkexcelapplicaiton ();Return False
  278. end function
  279. public function boolean of_checkfilename (string as_filename);Long li_Handle
  280. IF Trim(as_filename)="" Then REturn False
  281. If FileExists (as_filename ) Then
  282. IF MessageBox(inv_Res.Warning ,inv_Res.OF_Format( inv_Res.FileExists, as_FileName) ,Question!,YesNo!)=2 Then
  283. Return False
  284. END IF
  285. END IF
  286. //检查给定的文件路径是否可以写入
  287. li_Handle=FileOpen(as_filename,StreamMode!,Write!,LockWrite!,Replace!)
  288. FileClose(li_Handle)
  289. IF li_Handle=-1 OR IsNull(li_Handle) THEN
  290. MessageBox(inv_Res.Warning , inv_Res.OF_Format( inv_Res.FileWriteError, as_FileName) ,StopSign!)
  291. Return False
  292. END IF
  293. Return TRUE
  294. end function
  295. public function Boolean of_checksheetname (string as_name);IF Len(as_Name) > 31 Then
  296. Return False
  297. END IF
  298. IF Match(as_Name, "[:*?/\]") then
  299. Return False
  300. END IF
  301. Return TRUE
  302. end function
  303. public function string of_getcompanyname ();Return CompanyName
  304. end function
  305. public function integer of_report2excel (ref datawindow adw, readonly string as_filename);Long li ,li_cnt ,li_Row, li_Pos,li_GroupLevels,li_Handle ,li_Index
  306. String ls_Objects[],ls_Name, ls_Processing,ls_Temp
  307. Datastore lds
  308. DataWindowChild dwc ,dwcList[]
  309. IF Not IsValid(adw) Then
  310. REturn -1
  311. END IF
  312. //不是组合报表
  313. IF adw.Describe("DataWindow.Processing")<>"5" THEN
  314. Return -1
  315. END IF
  316. IF Trim(as_filename)="" Then REturn -1
  317. //检查给定的文件路径是否可以写入
  318. li_Handle=FileOpen(as_filename,StreamMode!,Write!,LockWrite!,Replace!)
  319. FileClose(li_Handle)
  320. IF li_Handle=-1 OR IsNull(li_Handle) THEN
  321. MessageBox(inv_Res.Warning ,inv_Res.OF_Format(inv_Res.FileWriteError, as_FileName) ,StopSign!)
  322. Return -1
  323. END IF
  324. ls_Temp=adw.Describe("datawindow.bands")
  325. li_pos=1
  326. Do While li_pos>0
  327. li_pos=Pos(ls_Temp,"header.",li_pos)
  328. IF li_pos>0 Then
  329. li_GroupLevels++
  330. li_pos++
  331. END IF
  332. Loop
  333. ls_Temp =" release 6 ; "+ &
  334. " datawindow(units=0 processing=1 ) " + &
  335. " header(height=0 ) " + &
  336. " detail(height=0 ) "+ &
  337. " summary(height=0 ) "+ &
  338. " table( "+&
  339. " column=(type=Char(100) updatewhereclause=no name=name dbname='name' initial='' ) " +&
  340. " column=(type=long updatewhereclause=no name=BandSeq dbname='BandSeq' initial='0' ) " +&
  341. " column=(type=long updatewhereclause=no name=x dbname='X' initial='0' ) " +&
  342. " column=(type=long updatewhereclause=no name=Y dbname='Y' initial='0' ) " +&
  343. " sort='BandSeq A, Y A ,X A' ) "
  344. lds=Create Datastore
  345. lds.Create(ls_Temp)
  346. li_cnt = OF_ParseToArray(adw.Describe("DataWindow.Objects"),"~t",ls_Objects)
  347. For li=1 To li_cnt
  348. ls_Name = ls_Objects[li]
  349. IF adw.Describe(ls_Name+".Type")<>"report" Then
  350. Continue
  351. END IF
  352. ls_Temp=adw.Describe(ls_Name+".Band")
  353. IF ls_Temp="?" OR ls_Temp="!" Then
  354. Continue
  355. END IF
  356. li_Index =0
  357. IF ls_Temp="header" Then
  358. li_Index =1
  359. ELSEIF ls_Temp="detail" Then
  360. li_Index=li_GroupLevels +2
  361. ELSEIF ls_Temp="summary" Then
  362. li_Index=li_GroupLevels*2 +3
  363. ELSEIF ls_Temp="footer" Then
  364. li_Index=li_GroupLevels*2 +4
  365. ELSE
  366. li_pos=Pos(ls_Temp,"header.",li_pos)
  367. IF li_pos>0 Then
  368. li_Index =Long(Mid(ls_Temp,li_Pos+1)) +1
  369. ELSE
  370. li_pos=Pos(ls_Temp,"trailer.",li_pos)
  371. IF li_pos>0 Then
  372. li_Index =Long(Mid(ls_Temp,li_Pos+1))+ 1+li_GroupLevels
  373. END IF
  374. END IF
  375. END IF
  376. li_Row =lds.InsertRow(0)
  377. lds.SetItem(li_Row,"BandSeq",li_Index)
  378. lds.SetItem(li_Row,"Name",ls_Name)
  379. lds.SetItem(li_Row,"X",Long(adw.Describe(ls_Name+".X")))
  380. lds.SetItem(li_Row,"Y",Long(adw.Describe(ls_Name+".Y")))
  381. Next
  382. lds.Sort()
  383. For li=1 To lds.RowCount()
  384. ls_Name = lds.GetItemString(li,"Name")
  385. adw.GetChild(ls_Name,dwc)
  386. IF Not IsValid(dwc) Then
  387. Continue
  388. END IF
  389. ls_Processing = dwc.Describe("DataWindow.Processing")
  390. IF ls_Processing<>'0' AND ls_Processing<>'1' Then
  391. Continue
  392. END IF
  393. dwcList[ UpperBound(dwcList)+1] = dwc
  394. Next
  395. IF UpperBound(dwcList)<=0 Then
  396. Return -1
  397. END IF
  398. RETURN OF_DW2Excel(dwcList, as_FileName)
  399. end function
  400. public function long of_parsetoarray (string as_source, string as_delimiter, ref string as_array[]);long ll_DelLen, ll_Pos, ll_Count, ll_Start, ll_Length
  401. string ls_holder
  402. String ls_Temp[]
  403. as_array= ls_Temp //清空原数组
  404. //Check for NULL
  405. IF IsNull(as_source) or IsNull(as_delimiter) Then
  406. long ll_null
  407. SetNull(ll_null)
  408. Return ll_null
  409. End If
  410. //Check for at leat one entry
  411. If Trim (as_source) = '' Then
  412. Return 0
  413. End If
  414. //Get the length of the delimeter
  415. ll_DelLen = Len(as_Delimiter)
  416. ll_Pos = Pos(Upper(as_source), Upper(as_Delimiter))
  417. //Only one entry was found
  418. if ll_Pos = 0 then
  419. as_Array[1] = as_source
  420. return 1
  421. end if
  422. //More than one entry was found - loop to get all of them
  423. ll_Count = 0
  424. ll_Start = 1
  425. Do While ll_Pos > 0
  426. //Set current entry
  427. ll_Length = ll_Pos - ll_Start
  428. ls_holder = Mid (as_source, ll_start, ll_length)
  429. // Update array and counter
  430. ll_Count ++
  431. as_Array[ll_Count] = ls_holder
  432. //Set the new starting position
  433. ll_Start = ll_Pos + ll_DelLen
  434. ll_Pos = Pos(Upper(as_source), Upper(as_Delimiter), ll_Start)
  435. Loop
  436. //Set last entry
  437. ls_holder = Mid (as_source, ll_start, Len (as_source))
  438. // Update array and counter if necessary
  439. if Len (ls_holder) > 0 then
  440. ll_count++
  441. as_Array[ll_Count] = ls_holder
  442. end if
  443. //Return the number of entries found
  444. Return ll_Count
  445. end function
  446. public subroutine of_setlicense (readonly string as_companyname, readonly string as_licensecode);CompanyName = as_CompanyName
  447. LICENSECODE = as_LicenseCode
  448. end subroutine
  449. public subroutine of_setlanguage (readonly string as_language, readonly string as_deffontname);is_Language = as_Language
  450. is_DefFontName = as_DefFontName
  451. IF IsValid(inv_Res) Then
  452. inv_Res.OF_SetLanguage(is_Language )
  453. END IF
  454. end subroutine
  455. public function Boolean of_openexcelfile (readonly string as_filename);Long li_Result
  456. OleObject xlapp //用于连接Excel
  457. xlApp=Create OleObject
  458. li_Result= xlApp.ConnectToNewObject( "Excel.Application" )
  459. IF li_Result < 0 Then
  460. MessageBox(inv_Res.Tips , inv_Res.RunExcelAppError )
  461. xlApp.DisConnectObject()
  462. Destroy xlApp
  463. Return False
  464. ELSE
  465. XlApp.Workbooks.Open(as_FileName)
  466. xlApp.ActiveWindow.WindowState= -4137 //最大化窗口
  467. xlApp.Visible = True
  468. xlApp.DisConnectObject()
  469. Return TRUE
  470. END IF
  471. Return False
  472. end function
  473. public subroutine of_setshowzerovalues (readonly boolean ab_show);ib_ShowZeroValues = ab_Show
  474. end subroutine
  475. public subroutine of_setwritebkcolor (readonly boolean ab_flag);ib_WriteBKColor =ab_flag
  476. end subroutine
  477. public subroutine of_setfreezetitles (readonly boolean ab_flag);ib_FreezeTitles =ab_Flag
  478. end subroutine
  479. public subroutine of_setshowgridlines (readonly boolean ab_show);ib_ShowGridLines =ab_Show
  480. end subroutine
  481. public subroutine of_setprocesssparse (readonly boolean ab_flag);ib_ProcessSparse = ab_Flag
  482. end subroutine
  483. public subroutine of_setfontsize (readonly unsignedinteger ai_fontsize);IF ai_FontSize>0 Then
  484. ii_DefFontSize = ai_FontSize
  485. END IF
  486. end subroutine
  487. public function string of_gettitle ();return '数据发送'
  488. end function
  489. on n_cst_dw2excel.create
  490. call super::create
  491. TriggerEvent( this, "constructor" )
  492. end on
  493. on n_cst_dw2excel.destroy
  494. TriggerEvent( this, "destructor" )
  495. call super::destroy
  496. end on
  497. event constructor;inv_Res = Create n_dw2xls_Resource
  498. inv_Res.OF_SetLanguage(is_Language)
  499. end event
  500. event destructor;IF IsValid(w_dw2xls_Progress) Then
  501. Return
  502. END IF
  503. IF IsValid(inv_Res) Then
  504. Destroy inv_Res
  505. END IF
  506. end event