n_dw2xls_layout.sru 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. $PBExportHeader$n_dw2xls_layout.sru
  2. forward
  3. global type n_dw2xls_layout from nonvisualobject
  4. end type
  5. type ustr_picture from structure within n_dw2xls_layout
  6. end type
  7. type ustr_graph from structure within n_dw2xls_layout
  8. end type
  9. end forward
  10. type ustr_picture from structure
  11. long row
  12. integer col
  13. string filename
  14. Long offsetx
  15. Long offsety
  16. Long width
  17. Long height
  18. end type
  19. type ustr_graph from structure
  20. long row
  21. long col
  22. n_dw2xls_requestor requestor
  23. datastore ds
  24. string name
  25. Long offsetx
  26. Long offsety
  27. Long width
  28. Long height
  29. end type
  30. global type n_dw2xls_layout from nonvisualobject
  31. end type
  32. global n_dw2xls_layout n_dw2xls_layout
  33. type prototypes
  34. Function ulong GetDC(ulong hwnd) library "user32.dll"
  35. Function ulong ReleaseDC(ulong hwnd,ulong hdc) library "user32.dll"
  36. function int GetDeviceCaps(ulong hdc, int nIndex) library "gdi32"
  37. end prototypes
  38. type variables
  39. DataStore ids_Objects
  40. Datastore ids_Columns
  41. Datastore ids_PageBreak
  42. Int ii_SheetIndex
  43. Int ii_Freeze_Rows
  44. Long il_Progress_Data
  45. Long il_Progress_Pictures
  46. Boolean ib_HasPictures
  47. Int ii_ColSpace =30
  48. Int ii_RowSpace=20
  49. Int ii_ObjSpace =100
  50. Int ii_LineSpace
  51. Long il_First_X1 =30000
  52. long il_Last_X2 = 0
  53. INT ii_LOGPIXELSX
  54. INT ii_LOGPIXELSY
  55. Private:
  56. Boolean ib_Nested=False
  57. Long il_RowCount
  58. //加入全部需要二次登记列位置的对象
  59. n_dw2xls_Object inv_Objects[]
  60. ustr_Picture istr_Pictures[]
  61. ustr_Graph istr_Graphs[] //图表
  62. constant long LOGPIXELSX =90 /* Logical pixels/inch in X */
  63. constant long LOGPIXELSY =90 /* Logical pixels/inch in Y */
  64. end variables
  65. forward prototypes
  66. public function integer of_columncount ()
  67. public function integer of_getcolspace ()
  68. public subroutine of_sortobject_x ()
  69. public subroutine of_addobject (n_dw2xls_object anv_object)
  70. public subroutine of_registcolumninfo ()
  71. public function integer of_writepictures (ref oleobject ole_excel, ref oleobject ole_sheet, ref n_dw2xls_progress anv_progress)
  72. public function boolean of_checkwritepictures ()
  73. public function Boolean of_haspictures ()
  74. public subroutine of_sethaspictures (readonly boolean ab_flag)
  75. public subroutine of_getcolumninfo ()
  76. public subroutine of_addhpagebreak (long al_row)
  77. public subroutine of_increaseprogress_picture (readonly long ai_increasevalue)
  78. public subroutine of_increaseprogress_data (readonly long al_increasevalue)
  79. public subroutine of_get_progresstotal (ref long al_progress_data, ref long al_progress_pictures)
  80. public subroutine of_updatecolumninfo ()
  81. public subroutine of_write_pagebreak (ref n_dw2xls_winapi anv_winapi, readonly unsignedlong al_hsheet)
  82. public subroutine of_write_columninfo (ref n_dw2xls_winapi anv_winapi, readonly unsignedlong al_hsheet)
  83. public function boolean of_isnested ()
  84. public subroutine of_setnested (boolean ab_flag)
  85. public function Long of_rowcount ()
  86. public subroutine of_setrowcount (readonly long al_count)
  87. public function Long of_get_next_x1 (long ai_x1)
  88. public function Long of_getcolumn_x1 (readonly integer ai_col)
  89. public function Long of_getcolumn_x2 (readonly long ai_col)
  90. public subroutine of_addgraph (readonly long ai_row, readonly long ai_col, n_dw2xls_requestor anv_requestor, readonly string as_name, readonly long ai_offsetx, readonly long ai_offsety, readonly long ai_width, readonly long ai_height)
  91. public function Long of_getcolumn_width (readonly integer ai_col)
  92. public function integer of_getendcolumn (long ai_x)
  93. public function integer of_getstartcolumn (long ai_x)
  94. public subroutine of_registcolumn (readonly long ai_x1)
  95. public subroutine of_updatecolumn_textwidth (readonly integer ai_col, readonly long ai_textwidth)
  96. public function Long of_get_pre_x1 (long ai_x1)
  97. public subroutine of_registobject (readonly long ai_x1, readonly boolean ab_x1)
  98. public subroutine of_addpicture (readonly long ai_row, readonly integer ai_col, readonly string as_filename, readonly long ai_offsetx, readonly long ai_offsety, readonly long ai_width, readonly long ai_height)
  99. end prototypes
  100. public function integer of_columncount ();Return ids_Columns.RowCount()
  101. end function
  102. public function integer of_getcolspace ();Return ii_ColSpace
  103. end function
  104. public subroutine of_sortobject_x ();Int li,lj,li_cnt
  105. Boolean lb_Stop
  106. n_dw2xls_Object lnv_Temp
  107. //先按X值按序,再按Y值排序
  108. li_cnt = UpperBound(inv_Objects)
  109. lb_Stop=False
  110. Do While Not lb_Stop
  111. lb_Stop=TRUE
  112. For li=1 TO li_cnt -1
  113. lj =li+1
  114. IF inv_Objects[lj ].x1<inv_Objects[li].x1 OR &
  115. ( inv_Objects[lj ].x1=inv_Objects[li].x1 AND inv_Objects[lj ].Y1<inv_Objects[li].Y1 ) Then
  116. lnv_Temp = inv_Objects[lj]
  117. inv_Objects[lj] =inv_Objects[li]
  118. inv_Objects[li] = lnv_Temp
  119. lb_Stop=False
  120. END IF
  121. Next
  122. Loop
  123. end subroutine
  124. public subroutine of_addobject (n_dw2xls_object anv_object);IF IsValid(anv_object) Then
  125. inv_objects[UpperBound(inv_objects)+1] = anv_object
  126. END IF
  127. end subroutine
  128. public subroutine of_registcolumninfo ();Int li, lj
  129. Long li_Pre_x1 ,li_Next_X1
  130. Boolean lb_flag
  131. n_dw2xls_Object lnv_Object
  132. OF_SortObject_X()
  133. For li=1 To UpperBound(inv_Objects)
  134. IF inv_Objects[li].ObjType="report" Then
  135. Continue
  136. END IF
  137. lnv_Object = inv_Objects[li]
  138. IF Not IsValid( lnv_Object.inv_LeftLine) Then
  139. /*------------------进一步判断是否需要登记该位置------------------------*/
  140. lb_Flag=False
  141. li_Pre_x1 = This.OF_Get_Pre_x1(lnv_Object.X1)
  142. li_Next_X1 =This.OF_Get_Next_x1(lnv_Object.X1)
  143. IF ABS(lnv_Object.X1 - li_Pre_x1)<=ii_ColSpace OR ABS(li_Next_X1 - lnv_Object.X1)<=ii_ColSpace Then
  144. Continue
  145. END IF
  146. For lj=li -1 TO 1 Step -1
  147. IF inv_Objects[lj].inv_Band <>lnv_Object.inv_Band Then
  148. Continue
  149. END IF
  150. //在对象与边线之间,前面是否有其它的对象,如果有,则登记该列的位置
  151. // IF inv_Objects[lj].Y1< lnv_Object.OF_GetTextRect_Y2() AND inv_Objects[lj].OF_GetTextRect_Y2() >lnv_Object.y1 Then
  152. // IF This.OF_Get_Pre_x1(inv_Objects[lj].OF_GetTextRect_X2() )>=li_Pre_x1 Then
  153. IF inv_Objects[lj].Y1< lnv_Object.OF_GetTextRect_Y2() AND inv_Objects[lj].OF_GetTextRect_Y2() >lnv_Object.y1 Then
  154. IF This.OF_Get_Pre_x1(inv_Objects[lj].X2 -ii_ColSpace )>=li_Pre_x1 OR lnv_Object.BorderStyle<>'0' Then
  155. This.OF_RegistObject(lnv_Object.X1 ,TRUE )
  156. lb_Flag=TRUE
  157. Exit
  158. ELSEIF inv_Objects[lj].x1<= li_Pre_x1 Then
  159. Exit
  160. END IF
  161. END IF
  162. Next
  163. //如果没有找到,为了输出的位置不会偏离太远,则登记该对象的起始位置
  164. IF lb_Flag=False AND (lnv_Object.X1 - li_Pre_x1)>400 AND lnv_Object.Alignment<>'1' Then
  165. This.OF_RegistObject(lnv_Object.X1, TRUE )
  166. END IF
  167. END IF
  168. Next
  169. For li=1 To UpperBound(inv_Objects)
  170. IF inv_Objects[li].ObjType="report" Then
  171. Continue
  172. END IF
  173. lnv_Object = inv_Objects[li]
  174. IF IsValid( lnv_Object.inv_LeftLine)=False AND IsValid( lnv_Object.inv_RightLine)=False AND &
  175. IsValid( lnv_Object.inv_TopLine)=False AND IsValid( lnv_Object.inv_BottomLine)=False AND &
  176. ( lnv_Object.BorderStyle='2' OR lnv_Object.BorderStyle='4' ) Then
  177. li_Next_X1 =This.OF_Get_Next_x1(lnv_Object.X2)
  178. IF ABS(li_Next_X1 - lnv_Object.X1)>50 Then
  179. This.OF_RegistObject(lnv_Object.X2, FALSE )
  180. END IF
  181. END IF
  182. Next
  183. end subroutine
  184. public function integer of_writepictures (ref oleobject ole_excel, ref oleobject ole_sheet, ref n_dw2xls_progress anv_progress);Long li, li_Count, li_Row, li_Col ,li_GraphCount ,li_Result
  185. Long li_Width, li_Height
  186. n_dw2xls_datawindow ldw
  187. li_Count = UpperBound(istr_Pictures)
  188. li_GraphCount = UpperBound(istr_Graphs )
  189. IF li_Count <= 0 And li_GraphCount <= 0 THEN
  190. RETURN 1
  191. END IF
  192. IF IsValid(ole_excel) = False Or IsValid(ole_sheet) = False Or IsValid(anv_progress) = False THEN
  193. RETURN -1
  194. END IF
  195. TRY
  196. FOR li = 1 To li_Count
  197. li_Row = istr_Pictures[li].Row
  198. li_Col = istr_Pictures[li].Col
  199. ole_sheet.Cells(li_Row ,li_Col ).Select()
  200. IF Right(istr_Pictures[li].Filename,1) = '\' Or FileExists(istr_Pictures[li].Filename) = False THEN CONTINUE //荣修改20170214
  201. ole_sheet.Pictures.Insert( istr_Pictures[li].Filename ).Select()
  202. ole_excel.Application.Selection.ShapeRange.LockAspectRatio = False
  203. ole_excel.Application.Selection.ShapeRange.Left = ole_sheet.Cells(li_Row, li_Col).Left + istr_Pictures[li].OffsetX
  204. ole_excel.Application.Selection.ShapeRange.Top = ole_sheet.Cells(li_Row,li_Col).Top + istr_Pictures[li].OffsetY
  205. ole_excel.Application.Selection.ShapeRange.Width = istr_Pictures[li].Width
  206. ole_excel.Application.Selection.ShapeRange.Height = istr_Pictures[li].Height
  207. anv_progress.OF_Progress(3)
  208. NEXT
  209. FOR li = 1 To li_GraphCount
  210. li_Result = 0
  211. IF IsValid(istr_Graphs[li].ds) THEN
  212. IF istr_Graphs[li].ds.Describe("DataWindow.Processing") = "3" THEN
  213. IF istr_Graphs[li].Requestor.OF_GetControlWidth() > 0 THEN
  214. li_Width = istr_Graphs[li].Requestor.OF_GetControlWidth()
  215. ELSE
  216. li_Width = istr_Graphs[li].Width
  217. END IF
  218. IF istr_Graphs[li].Requestor.OF_GetControlHeight() > 0 THEN
  219. li_Height = istr_Graphs[li].Requestor.OF_GetControlHeight()
  220. ELSE
  221. li_Height = istr_Graphs[li].Height
  222. END IF
  223. IF li_Width <= 0 Or li_Height <= 0 THEN
  224. CONTINUE
  225. END IF
  226. anv_progress.iw_progress.OpenUserObject(ldw,anv_progress.iw_progress.Width -40,0 )
  227. ldw.Resize(li_Width,li_Height)
  228. ldw.Create(istr_Graphs[li].ds.Describe("DataWindow.Syntax"))
  229. ldw.ImportString(istr_Graphs[li].ds.Describe("DataWindow.Data"))
  230. ldw.SetRedraw(True)
  231. li_Result = ldw.Clipboard( istr_Graphs[li].Name)
  232. anv_progress.iw_progress.CloseUserObject(ldw)
  233. Destroy istr_Graphs[li].ds
  234. ELSE
  235. li_Result = istr_Graphs[li].ds.Clipboard( istr_Graphs[li].Name)
  236. Destroy istr_Graphs[li].ds
  237. END IF
  238. ELSE
  239. li_Result = istr_Graphs[li].Requestor.OF_Clipboard( istr_Graphs[li].Name)
  240. END IF
  241. IF li_Result <> 1 THEN
  242. CONTINUE
  243. END IF
  244. li_Row = istr_Graphs[li].Row
  245. li_Col = istr_Graphs[li].Col
  246. ole_sheet.Cells(li_Row ,li_Col ).Select()
  247. ole_excel.Application.ActiveSheet.Paste()
  248. ole_excel.Application.Selection.ShapeRange.LockAspectRatio = False
  249. ole_excel.Application.Selection.ShapeRange.Left = ole_sheet.Cells(li_Row, li_Col).Left + istr_Graphs[li].OffsetX
  250. ole_excel.Application.Selection.ShapeRange.Top = ole_sheet.Cells(li_Row,li_Col).Top + istr_Graphs[li].OffsetY
  251. ole_excel.Application.Selection.ShapeRange.Width = istr_Graphs[li].Width
  252. ole_excel.Application.Selection.ShapeRange.Height = istr_Graphs[li].Height
  253. anv_progress.OF_Progress(3)
  254. NEXT
  255. ole_sheet.Cells(ii_Freeze_Rows+1,1).Select()
  256. ole_sheet.Cells(1,1).Select()
  257. li_Result = 1
  258. //编译为DLL时,不能处理 OLERuntimeError 的异常
  259. Catch(OLERuntimeError oleError)
  260. li_Result = -1
  261. Catch(RuntimeError er)
  262. li_Result = -1
  263. END TRY
  264. RETURN li_Result
  265. end function
  266. public function boolean of_checkwritepictures ();Return ( UpperBound(istr_Pictures) +UpperBound(istr_Graphs)) >0
  267. end function
  268. public function Boolean of_haspictures ();Return ib_HasPictures
  269. end function
  270. public subroutine of_sethaspictures (readonly boolean ab_flag);ib_HasPictures =ab_flag
  271. end subroutine
  272. public subroutine of_getcolumninfo ();Long li,li_Row
  273. Long li_x1, li_x2
  274. Long li_Pre_x1, li_Pre_x2, li_Next_x1, li_Next_x2
  275. String ls_Border
  276. ids_Columns.Sort()
  277. For li=1 TO ids_Columns.RowCount() -1
  278. ids_Columns.SetItem(li,"x2",ids_Columns.GetItemNumber(li+1,"x1") )
  279. Next
  280. //删除最后一行
  281. ids_Columns.DeleteRow(ids_Columns.RowCount())
  282. ids_Columns.Sort()
  283. end subroutine
  284. public subroutine of_addhpagebreak (long al_row);Long li_Row
  285. IF al_Row<=0 Then Return
  286. li_Row= ids_PageBreak.Find("RowNum="+String(al_Row),1,ids_PageBreak.RowCount())
  287. IF li_Row<=0 Then
  288. li_Row = ids_PageBreak.InsertRow(0)
  289. ids_PageBreak.SetItem(li_Row,"RowNum",al_Row)
  290. END IF
  291. end subroutine
  292. public subroutine of_increaseprogress_picture (readonly long ai_increasevalue);il_Progress_Pictures+=ai_IncreaseValue
  293. end subroutine
  294. public subroutine of_increaseprogress_data (readonly long al_increasevalue);il_Progress_Data+=al_increaseValue
  295. end subroutine
  296. public subroutine of_get_progresstotal (ref long al_progress_data, ref long al_progress_pictures);al_Progress_Data +=il_Progress_Data
  297. al_Progress_Pictures+=il_Progress_Pictures
  298. end subroutine
  299. public subroutine of_updatecolumninfo ();Long li ,li_TextWidth ,li_X2
  300. For li=1 To ids_Columns.RowCount()
  301. li_TextWidth= ids_Columns.GetItemNumber(li,"MaxTextWidth")
  302. IF li_TextWidth>0 Then
  303. li_X2 = ids_Columns.GetItemNumber(li,"X1")+li_TextWidth
  304. IF (li_X2 - ids_Columns.GetItemNumber(li,"X2"))<=ii_ColSpace Then
  305. ids_Columns.SetItem(li,"X2",li_X2 )
  306. IF li <ids_Columns.RowCount() Then
  307. ids_Columns.SetItem(li+1,"X1",li_X2)
  308. END IF
  309. END IF
  310. END IF
  311. Next
  312. //ids_Columns.SaveAS("C:\Columns.Txt",Text!,True)
  313. end subroutine
  314. public subroutine of_write_pagebreak (ref n_dw2xls_winapi anv_winapi, readonly unsignedlong al_hsheet);
  315. Long li
  316. ids_PageBreak.Sort()
  317. For li=1 To ids_PageBreak.RowCount()
  318. anv_WinApi.AddHPageBreak(al_hSheet, ids_PageBreak.GetItemNumber(li,"RowNum"))
  319. Next
  320. end subroutine
  321. public subroutine of_write_columninfo (ref n_dw2xls_winapi anv_winapi, readonly unsignedlong al_hsheet);Long li ,li_Width
  322. ids_Columns.Sort()
  323. For li=1 To ids_Columns.RowCount()
  324. //由于Excel单元格的可显示区域大小,不同于PB,为了完整显示单元格的内容,列的宽度加上 4Pixels
  325. li_Width = ids_Columns.GetItemNumber(li,"x2") - ids_Columns.GetItemNumber(li ,"x1")
  326. li_Width = Ceiling( ( UnitsToPixels(li_Width,XUnitsToPixels!)+4 ) *256/8)
  327. anv_winapi.SetColumnWidth(al_hSheet, li, li_Width)
  328. Next
  329. end subroutine
  330. public function boolean of_isnested ();Return ib_Nested
  331. end function
  332. public subroutine of_setnested (boolean ab_flag);ib_Nested =ab_flag
  333. end subroutine
  334. public function Long of_rowcount ();Return il_RowCount
  335. end function
  336. public subroutine of_setrowcount (readonly long al_count);il_RowCount = al_Count
  337. end subroutine
  338. public function Long of_get_next_x1 (long ai_x1);Long li_Row ,li_Next_x1
  339. ids_Columns.Sort()
  340. li_Row = ids_Columns.Find("x1>= "+String(ai_x1 - ii_ColSpace), 1, ids_Columns.RowCount())
  341. IF li_Row >0 Then
  342. li_Next_x1= ids_Columns.GetItemNumber(li_Row,"x1")
  343. IF li_Next_x1<ai_x1 Then
  344. li_Next_x1 =ai_x1
  345. END IF
  346. END IF
  347. Return li_Next_x1
  348. end function
  349. public function Long of_getcolumn_x1 (readonly integer ai_col);IF ai_Col>0 AND ai_Col<=ids_Columns.RowCount() Then
  350. Return ids_Columns.GetItemNumber(ai_Col, "x1")
  351. END IF
  352. RETURN 0
  353. end function
  354. public function Long of_getcolumn_x2 (readonly long ai_col);IF ai_Col>0 AND ai_Col<=ids_Columns.RowCount() Then
  355. Return ids_Columns.GetItemNumber(ai_Col, "x2")
  356. END IF
  357. RETURN 0
  358. end function
  359. public subroutine of_addgraph (readonly long ai_row, readonly long ai_col, n_dw2xls_requestor anv_requestor, readonly string as_name, readonly long ai_offsetx, readonly long ai_offsety, readonly long ai_width, readonly long ai_height);Long li_Index
  360. Datastore lds
  361. li_Index = UpperBound(istr_graphs) +1
  362. istr_graphs[li_Index].Requestor =anv_Requestor
  363. istr_graphs[li_Index].Row =ai_Row
  364. istr_graphs[li_Index].Col =ai_Col
  365. istr_graphs[li_Index].Name =as_name
  366. istr_graphs[li_Index].offsetX =UnitsToPixels(ai_offsetX,XUnitsToPixels!)/ii_LOGPIXELSX*72 //把PB的Units转为 Excel的单位
  367. istr_graphs[li_Index].OffsetY =UnitsToPixels(ai_OffsetY,YUnitsToPixels!)/ii_LOGPIXELSY*72
  368. IF anv_Requestor.OF_GetProcessing()='3' Then
  369. IF anv_Requestor.OF_GetControlWidth()>0 Then
  370. istr_graphs[li_Index].Width =UnitsToPixels(anv_Requestor.OF_GetControlWidth(),XUnitsToPixels!)/ii_LOGPIXELSX*72
  371. ELSE
  372. istr_graphs[li_Index].Width =UnitsToPixels(ai_width,XUnitsToPixels!)/ii_LOGPIXELSX*72
  373. END IF
  374. IF anv_Requestor.OF_GetControlHeight()>0 Then
  375. istr_graphs[li_Index].Height =UnitsToPixels(anv_Requestor.OF_GetControlHeight(),YUnitsToPixels!)/ii_LOGPIXELSY*72
  376. ELSE
  377. istr_graphs[li_Index].Height =UnitsToPixels(ai_Height,YUnitsToPixels!)/ii_LOGPIXELSY*72
  378. END IF
  379. ELSE
  380. istr_graphs[li_Index].Width =UnitsToPixels(ai_width,XUnitsToPixels!)/ii_LOGPIXELSX*72
  381. istr_graphs[li_Index].Height =UnitsToPixels(ai_Height,YUnitsToPixels!)/ii_LOGPIXELSY*72
  382. END IF
  383. IF anv_Requestor.OF_IsChild() OR anv_Requestor.OF_IsDataWindowChild() THen //先缓存数据,因为Nest Report的数据窗口,在输出一行后,会删除该行数据
  384. lds = Create Datastore
  385. lds.Create(anv_Requestor.OF_Describe("DataWindow.Syntax"))
  386. lds.ImportString(anv_Requestor.OF_Describe("DataWindow.Data"))
  387. istr_graphs[li_Index].ds = lds
  388. END IF
  389. end subroutine
  390. public function Long of_getcolumn_width (readonly integer ai_col);IF ai_Col>0 AND ai_Col<=ids_Columns.RowCount() Then
  391. Return ids_Columns.GetItemNumber(ai_Col, "x2") - ids_Columns.GetItemNumber(ai_Col, "x1")
  392. END IF
  393. Return 0
  394. end function
  395. public function integer of_getendcolumn (long ai_x);Int li_Find
  396. li_Find = ids_Columns.Find("x2= "+String(ai_x), 1, ids_Columns.RowCount() )
  397. IF li_Find<=0 Then
  398. li_Find = ids_Columns.Find("x2<= "+String(ai_x+ii_ColSpace)+" AND x2>= "+String(ai_x - ii_ColSpace),1,ids_Columns.RowCount())
  399. IF li_Find<=0 Then
  400. li_Find = ids_Columns.Find("x1> "+String(ai_x -ii_ColSpace), 1 ,ids_Columns.RowCount() )
  401. IF li_Find<=0 Then
  402. li_Find=ids_Columns.Find("X2<"+String(ai_x +ii_ColSpace),ids_Columns.RowCount() ,1)
  403. IF li_Find<=0 Then
  404. li_Find= ids_Columns.RowCount()
  405. ELSE
  406. li_Find = li_Find +1
  407. END IF
  408. ELSE
  409. li_Find = li_Find -1
  410. END IF
  411. // ELSEIF li_Find<ids_Columns.RowCount() Then //是否更靠近下一列?
  412. // IF ABS(ids_Columns.GetItemNumber(li_Find+1,"X2") - ai_X) <ABS(ids_Columns.GetItemNumber(li_Find,"X2") - ai_X) Then
  413. // li_Find++
  414. // END IF
  415. END IF
  416. END IF
  417. IF li_Find<=0 Then
  418. li_Find =1
  419. ELSEIF li_Find> ids_Columns.RowCount() Then
  420. li_Find = ids_Columns.RowCount()
  421. END IF
  422. Return li_Find
  423. end function
  424. public function integer of_getstartcolumn (long ai_x);Int li_Find
  425. li_Find = ids_Columns.Find("x1= "+String(ai_x), 1, ids_Columns.RowCount() )
  426. IF li_Find<=0 Then
  427. li_Find = ids_Columns.Find("x1<= "+String(ai_x+ii_ColSpace)+" AND x1>= "+String(ai_x - ii_ColSpace),1,ids_Columns.RowCount())
  428. IF li_Find<=0 Then
  429. li_Find = ids_Columns.Find("x1> "+String(ai_x + ii_ColSpace), 1, ids_Columns.RowCount() )
  430. IF li_Find<=0 Then
  431. li_Find=ids_Columns.Find("X2<"+String(ai_x +ii_ColSpace),ids_Columns.RowCount() ,1)
  432. IF li_Find<=0 Then
  433. li_Find= ids_Columns.RowCount()
  434. ELSE
  435. li_Find = li_Find +1
  436. END IF
  437. ELSE
  438. li_Find = li_Find -1
  439. IF li_Find>0 AND li_Find<ids_Columns.RowCount() Then
  440. IF ids_Columns.GetItemNumber(li_Find,"X2") > ai_X Then
  441. li_Find = li_Find +1
  442. END IF
  443. END IF
  444. END IF
  445. END IF
  446. END IF
  447. IF li_Find<=0 Then
  448. li_Find =1
  449. ELSEIF li_Find> ids_Columns.RowCount() Then
  450. li_Find = ids_Columns.RowCount()
  451. END IF
  452. Return li_Find
  453. end function
  454. public subroutine of_registcolumn (readonly long ai_x1);//如是是注册细节区的对象,则按精准定义
  455. Long li_Row
  456. li_Row = ids_Columns.Find("x1="+String(ai_x1),1,ids_Columns.RowCount())
  457. IF li_Row<=0 Then
  458. li_Row = ids_Columns.InsertRow(0)
  459. ids_Columns.SetItem(li_Row,"x1",ai_x1)
  460. END IF
  461. ids_Columns.Sort()
  462. end subroutine
  463. public subroutine of_updatecolumn_textwidth (readonly integer ai_col, readonly long ai_textwidth);IF ai_Col>0 AND ai_Col<=ids_Columns.RowCount() Then
  464. IF ids_Columns.GetItemNumber(ai_Col, "MaxTextWidth")<ai_textwidth Then
  465. ids_Columns.SetItem(ai_Col,'MaxTextWidth', ai_textwidth)
  466. END IF
  467. END IF
  468. end subroutine
  469. public function Long of_get_pre_x1 (long ai_x1);Long li_Row ,li_Pre_x1
  470. ids_Columns.Sort()
  471. li_Row = ids_Columns.Find("x1<= "+String(ai_x1 -ii_ColSpace),ids_Columns.RowCount(), 1)
  472. IF li_Row >0 Then
  473. li_Pre_x1= ids_Columns.GetItemNumber(li_Row,"x1")
  474. END IF
  475. li_Row = ids_Objects.Find("x1<= "+String(ai_x1 -ii_ColSpace),ids_Objects.RowCount(), 1)
  476. IF li_Row >0 Then
  477. IF ids_Objects.GetItemNumber(li_Row,"x1")>li_Pre_x1 Then
  478. li_Pre_x1= ids_Objects.GetItemNumber(li_Row,"x1")
  479. END IF
  480. END IF
  481. Return li_Pre_x1
  482. end function
  483. public subroutine of_registobject (readonly long ai_x1, readonly boolean ab_x1);//注册非细节区的对象,则不按精准对象定位
  484. Long li_Row
  485. li_Row = ids_Columns.Find("x1<="+String(ai_x1+ii_ColSpace)+" AND X1>= "+String(ai_x1 - ii_ColSpace) ,1,ids_Columns.RowCount())
  486. IF li_Row<=0 Then
  487. li_Row = ids_Columns.InsertRow(0)
  488. ids_Columns.SetItem(li_Row,"x1",ai_x1)
  489. ELSE
  490. IF ab_x1 Then
  491. IF ids_Columns.GetItemNumber(li_Row,"X1")>ai_X1 Then
  492. ids_Columns.SetItem(li_Row,"X1",ai_X1)
  493. END IF
  494. END IF
  495. END IF
  496. ids_Columns.Sort()
  497. end subroutine
  498. public subroutine of_addpicture (readonly long ai_row, readonly integer ai_col, readonly string as_filename, readonly long ai_offsetx, readonly long ai_offsety, readonly long ai_width, readonly long ai_height);Long li_Index
  499. String new_FileName
  500. li_Index = UpperBound(istr_Pictures) +1
  501. istr_Pictures[li_Index].Row = ai_Row
  502. istr_Pictures[li_Index].Col = ai_Col
  503. istr_Pictures[li_Index].Filename = as_FileName
  504. istr_Pictures[li_Index].offsetX = UnitsToPixels(ai_offsetX,XUnitsToPixels!)/ii_LOGPIXELSX*72 //把PB的Units转为 Excel的单位
  505. istr_Pictures[li_Index].OffsetY = UnitsToPixels(ai_OffsetY,YUnitsToPixels!)/ii_LOGPIXELSY*72
  506. istr_Pictures[li_Index].Width = UnitsToPixels(ai_width,XUnitsToPixels!)/ii_LOGPIXELSX*72
  507. istr_Pictures[li_Index].Height = UnitsToPixels(ai_Height,YUnitsToPixels!)/ii_LOGPIXELSY*72
  508. end subroutine
  509. on n_dw2xls_layout.create
  510. call super::create
  511. TriggerEvent( this, "constructor" )
  512. end on
  513. on n_dw2xls_layout.destroy
  514. TriggerEvent( this, "destructor" )
  515. call super::destroy
  516. end on
  517. event constructor;String ls_Syntax
  518. Long hdc
  519. n_dw2xls_WinApi lnv_Api
  520. ls_Syntax =" release 6; "+ &
  521. " datawindow(units=0 processing=1 ) " + &
  522. " header(height=0 ) " + &
  523. " detail(height=0 ) "+ &
  524. " summary(height=0 ) "+ &
  525. " table( "+&
  526. " column=(type=long updatewhereclause=no name=x1 dbname='x1' initial='0' ) " +&
  527. " column=(type=long updatewhereclause=no name=x2 dbname='x2' initial='0' ) " +&
  528. " column=(type=long updatewhereclause=no name=textwidth dbname='textwidth' initial='0' ) " +&
  529. " column=(type=long updatewhereclause=no name=textheight dbname='textheight' initial='0' ) " +&
  530. " column=(type=char(1) updatewhereclause=no name=Alignment dbname='Alignment' initial='0' )"+&
  531. " column=(type=char(1) updatewhereclause=no name=Border dbname='Border' initial='0' )"+&
  532. " sort='x1 A, X2 A ' ) "
  533. ids_Objects = Create DataStore
  534. ids_Objects.Create( ls_Syntax)
  535. ls_Syntax =" release 6; "+ &
  536. " datawindow(units=0 processing=1 ) " + &
  537. " header(height=0 ) " + &
  538. " detail(height=0 ) "+ &
  539. " summary(height=0 ) "+ &
  540. " table( "+&
  541. " column=(type=long updatewhereclause=no name=x1 dbname='x1' initial='0' ) " +&
  542. " column=(type=long updatewhereclause=no name=x2 dbname='x2' initial='0' ) " +&
  543. " column=(type=long updatewhereclause=no name=MaxTextWidth dbname='MaxTextWidth' initial='0' ) " +&
  544. " sort='x1 A, x2 A ' ) "
  545. ids_Columns = Create DataStore
  546. ids_Columns.Create( ls_Syntax)
  547. ls_Syntax =" release 6; "+ &
  548. " datawindow(units=0 processing=1 ) " + &
  549. " header(height=0 ) " + &
  550. " detail(height=0 ) "+ &
  551. " summary(height=0 ) "+ &
  552. " table( "+&
  553. " column=(type=long updatewhereclause=no name=RowNum dbname='RowNum' initial='0' ) " +&
  554. " sort='RowNum A ' ) "
  555. ids_PageBreak = Create DataStore
  556. ids_PageBreak.Create( ls_Syntax)
  557. hdc =GetDC(0)
  558. ii_LOGPIXELSX =GetDeviceCaps(hdc, LOGPIXELSX)
  559. ii_LOGPIXELSY=GetDeviceCaps(hdc , LOGPIXELSY)
  560. ReleaseDC(0,hdc)
  561. end event
  562. event destructor;Int li
  563. Destroy ids_Objects
  564. Destroy ids_Columns
  565. For li =1 TO UpperBound(istr_Graphs)
  566. IF IsValid(istr_Graphs[li].ds) Then
  567. Destroy istr_Graphs[li].ds
  568. END IF
  569. Next
  570. end event