控制多个datawindow数据合并成一个excel导出【PB】

  1. string ls_path, ls_file
  2. double ll_len_path, ll_len_file
  3. int li_rc
  4. Long j
  5. if dw_preview.RowCount() > 0 then
  6. li_rc = GetFileSaveName ( "Select File", ls_path, ls_file, "XLS", "Excel Files (*.XLS), *.XLS,All Files (*.*)" , "", 32770)
  7. //get the filename from user
  8. ll_len_file=LastPos(ls_file,'.')
  9. if li_rc = 1 then
  10. OLEObject l_oleobject_excel
  11. l_oleobject_excel = CREATE OLEObject
  12. l_oleobject_excel.ConnectToNewObject('excel.application')
  13. l_oleobject_excel.Visible = False
  14. //rename
  15. l_oleobject_excel.Workbooks.add()
  16. ls_file=left(ls_file, long(ll_len_file)-1)+'_1'
  17. l_oleobject_excel.workbooks(1).worksheets(1).name = ls_file
  18. ls_file=left(ls_file, long(ll_len_file)-1)+'_2'
  19. l_oleobject_excel.workbooks(1).worksheets(2).name = ls_file
  20. ls_file=left(ls_file, long(ll_len_file)-1)+'_3'
  21. l_oleobject_excel.workbooks(1).worksheets(3).name = ls_file
  22. //insert data from dw to sheet1
  23. for j=1 to dw_saveas_sku_alias.rowcount()
  24. //header
  25. l_oleobject_excel.workbooks(1).worksheets(1).cells(j,1).value = 'sku'
  26. l_oleobject_excel.workbooks(1).worksheets(1).cells(j,2).value = 'alias'
  27. l_oleobject_excel.workbooks(1).worksheets(1).cells(j,3).value = 'desc'
  28. l_oleobject_excel.workbooks(1).worksheets(1).cells(j,4).value = 'default_alias'
  29. l_oleobject_excel.workbooks(1).worksheets(1).cells(j,5).value = 'pack_wt'
  30. l_oleobject_excel.workbooks(1).worksheets(1).cells(j,6).value = 'net_wt'
  31. //detail
  32. l_oleobject_excel.workbooks(1).worksheets(1).cells(j+1,1).value = dw_saveas_sku_alias.object.sku_alias_sku[j]
  33. l_oleobject_excel.workbooks(1).worksheets(1).cells(j+1,2).value = dw_saveas_sku_alias.object.sku_alias_sku_alias[j]
  34. l_oleobject_excel.workbooks(1).worksheets(1).cells(j+1,3).value = dw_saveas_sku_alias.object.sku_alias_alias_desc[j]
  35. l_oleobject_excel.workbooks(1).worksheets(1).cells(j+1,4).value = dw_saveas_sku_alias.object.sku_alias_default_alias[j]
  36. l_oleobject_excel.workbooks(1).worksheets(1).cells(j+1,5).value = dw_saveas_sku_alias.object.sku_alias_pack_wt[j]
  37. l_oleobject_excel.workbooks(1).worksheets(1).cells(j+1,6).value = dw_saveas_sku_alias.object.sku_alias_net_wt[j]
  38. next
  39. //insert data from dw to sheet2
  40. for j=1 to dw_saveas_sku_alias.rowcount()
  41. //header
  42. l_oleobject_excel.workbooks(1).worksheets(2).cells(j,1).value = 'sku'
  43. l_oleobject_excel.workbooks(1).worksheets(2).cells(j,2).value = 'alias'
  44. l_oleobject_excel.workbooks(1).worksheets(2).cells(j,3).value = 'desc'
  45. l_oleobject_excel.workbooks(1).worksheets(2).cells(j,4).value = 'default_alias'
  46. l_oleobject_excel.workbooks(1).worksheets(2).cells(j,5).value = 'pack_wt'
  47. l_oleobject_excel.workbooks(1).worksheets(2).cells(j,6).value = 'net_wt'
  48. //detail
  49. l_oleobject_excel.workbooks(1).worksheets(2).cells(j+1,1).value = dw_saveas_sku_alias.object.sku_alias_sku[j]
  50. l_oleobject_excel.workbooks(1).worksheets(2).cells(j+1,2).value = dw_saveas_sku_alias.object.sku_alias_sku_alias[j]
  51. l_oleobject_excel.workbooks(1).worksheets(2).cells(j+1,3).value = dw_saveas_sku_alias.object.sku_alias_alias_desc[j]
  52. l_oleobject_excel.workbooks(1).worksheets(2).cells(j+1,4).value = dw_saveas_sku_alias.object.sku_alias_default_alias[j]
  53. l_oleobject_excel.workbooks(1).worksheets(2).cells(j+1,5).value = dw_saveas_sku_alias.object.sku_alias_pack_wt[j]
  54. l_oleobject_excel.workbooks(1).worksheets(2).cells(j+1,6).value = dw_saveas_sku_alias.object.sku_alias_net_wt[j]
  55. next
  56. //insert data from dw to sheet3
  57. for j=1 to dw_saveas_sku_alias.rowcount()
  58. //header
  59. l_oleobject_excel.workbooks(1).worksheets(3).cells(j,1).value = 'sku'
  60. l_oleobject_excel.workbooks(1).worksheets(3).cells(j,2).value = 'alias'
  61. l_oleobject_excel.workbooks(1).worksheets(3).cells(j,3).value = 'desc'
  62. l_oleobject_excel.workbooks(1).worksheets(3).cells(j,4).value = 'default_alias'
  63. l_oleobject_excel.workbooks(1).worksheets(3).cells(j,5).value = 'pack_wt'
  64. l_oleobject_excel.workbooks(1).worksheets(3).cells(j,6).value = 'net_wt'
  65. //detail
  66. l_oleobject_excel.workbooks(1).worksheets(3).cells(j+1,1).value = dw_saveas_sku_alias.object.sku_alias_sku[j]
  67. l_oleobject_excel.workbooks(1).worksheets(3).cells(j+1,2).value = dw_saveas_sku_alias.object.sku_alias_sku_alias[j]
  68. l_oleobject_excel.workbooks(1).worksheets(3).cells(j+1,3).value = dw_saveas_sku_alias.object.sku_alias_alias_desc[j]
  69. l_oleobject_excel.workbooks(1).worksheets(3).cells(j+1,4).value = dw_saveas_sku_alias.object.sku_alias_default_alias[j]
  70. l_oleobject_excel.workbooks(1).worksheets(3).cells(j+1,5).value = dw_saveas_sku_alias.object.sku_alias_pack_wt[j]
  71. l_oleobject_excel.workbooks(1).worksheets(3).cells(j+1,6).value = dw_saveas_sku_alias.object.sku_alias_net_wt[j]
  72. next
  73. //save as excel
  74. l_oleobject_excel.ActiveWorkbook.SaveAs(ls_path)
  75. l_oleobject_excel.Application.DisplayAlerts = False
  76. l_oleobject_excel.workbooks.Close()
  77. l_oleobject_excel.Quit
  78. l_oleobject_excel.DisconnectObject ( )
  79. DESTROY l_oleobject_excel
  80. end if
  81. end if

你可能感兴趣的:(Excel,报表,PowerBuilder)