Import Excel Data to Pb DW

Source: Internet
Author: User
For more information, see my resources.

Http://download.csdn.net/user/happyflystone

 
  1. // ================================================ ====================================
  2. // Event: cb_1: clicked ()
  3. //--------------------------------------------------------------------
  4. // Description: Two Methods
  5. // 1. Read data in one row through an array (defining data is troublesome)
  6. // 2. directly use the clipboard
  7. // Method used by netizens
  8. //--------------------------------------------------------------------
  9. // Arguments :( none)
  10. //--------------------------------------------------------------------
  11. // Returns:
  12. //--------------------------------------------------------------------
  13. // Author: flystone Date: 2008-09-13 17:31:44 Sep
  14. //--------------------------------------------------------------------
  15. // Modify history:
  16. //
  17. //--------------------------------------------------------------------
  18. // Copyright (c) 2007-008 flystone Co., Ltd! All rights reserved.
  19. // ================================================ ====================================
  20. String ls_path, ls_name
  21. Ls_path = "C:/Documents and Settings/administrator. flystone/desktop/new folder (3)/test.xls"
  22. Dw_1.reset () // clean DW
  23. String a [1000,1000]
  24. Integer I, j, li_ret
  25. Li_ret = getfileopenname ('select XLS ', ls_path, ls_name, "xls", "Excel (*. xls), *. xls ")
  26. If li_ret <> 1 then return
  27. Oleobject excelserver
  28. Int li_connecterr
  29. Excelserver = create oleobject
  30. Li_connecterr = excelserver. connecttonewobject ("Excel. application ")
  31. If li_connecterr <0 then
  32. Choose case li_connecterr
  33. Case-1
  34. MessageBox ('error message', 'invalid call ')
  35. Case-2
  36. MessageBox ('error message', 'class name not discovered ')
  37. Case-3
  38. MessageBox ('error message', 'object cannot be create ')
  39. Case-4
  40. MessageBox ('error message', 'file cannot be connected ')
  41. Case-5
  42. MessageBox ('error message', 'cannot connect current object ')
  43. Case-6
  44. MessageBox ('error message', 'invalid file ')
  45. Case-7
  46. MessageBox ("error prompt", "the file does not exist or has been opened ")
  47. Case-8
  48. MessageBox ("error message", "the server cannot load the selected file ")
  49. Case-9
  50. MessageBox ("error prompt", "other errors ")
  51. End choose
  52. Return
  53. End if
  54. Excelserver. workbooks. Open (ls_path, 0, false)
  55. // After modifying the xls file, do you need to give a warning when closing the file.
  56. Excelserver. application. displayalerts = false
  57. // Select the sheets table
  58. // Excelserver. activeworkbook. worksheets ("sheet2"). Select ()
  59. // Method 1:
  60. Int li_rows, li_columns
  61. Li_rows = excelserver. activesheet. usedrange. Rows. Count // get the total number of rows
  62. Li_columns = excelserver. activesheet. usedrange. Columns. Count // get the total number of rows
  63. // # Of columns in Excel
  64. Sle_2.text = trim (string (li_rows ))
  65. // # Of rows in Excel
  66. Sle_1.text = string (li_columns)
  67. // Lole_sheet = ole_1.application.activeworkbook.worksheets [1] // obtain the first sheet of the current work.
  68. For I = 1 to li_rows
  69. Dw_1.insertrow (0)
  70. For j = 1 to li_columns
  71. A [I, j] = string (excelserver. activesheet. cells (I, j). value)
  72. Dw_1.setitem (I, j, a [I, j])
  73. End
  74. End
  75. // Method 2: Use the clipboard
  76. Excelserver. activesheet. cells. Copy
  77. Dw_1.importclipboard (2) // The title required for data import
  78. Excelserver. application. activeworkbook. Close (false)
  79. Excelserver. application. Quit ()
  80. Excelserver. disconnectobject ()

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.