For more information, see my resources.
Http://download.csdn.net/user/happyflystone
- // ================================================ ====================================
- // Event: cb_1: clicked ()
- //--------------------------------------------------------------------
- // Description: Two Methods
- // 1. Read data in one row through an array (defining data is troublesome)
- // 2. directly use the clipboard
- // Method used by netizens
- //--------------------------------------------------------------------
- // Arguments :( none)
- //--------------------------------------------------------------------
- // Returns:
- //--------------------------------------------------------------------
- // Author: flystone Date: 2008-09-13 17:31:44 Sep
- //--------------------------------------------------------------------
- // Modify history:
- //
- //--------------------------------------------------------------------
- // Copyright (c) 2007-008 flystone Co., Ltd! All rights reserved.
- // ================================================ ====================================
- String ls_path, ls_name
- Ls_path = "C:/Documents and Settings/administrator. flystone/desktop/new folder (3)/test.xls"
- Dw_1.reset () // clean DW
- String a [1000,1000]
- Integer I, j, li_ret
- Li_ret = getfileopenname ('select XLS ', ls_path, ls_name, "xls", "Excel (*. xls), *. xls ")
- If li_ret <> 1 then return
- Oleobject excelserver
- Int li_connecterr
- Excelserver = create oleobject
- Li_connecterr = excelserver. connecttonewobject ("Excel. application ")
- If li_connecterr <0 then
- Choose case li_connecterr
- Case-1
- MessageBox ('error message', 'invalid call ')
- Case-2
- MessageBox ('error message', 'class name not discovered ')
- Case-3
- MessageBox ('error message', 'object cannot be create ')
- Case-4
- MessageBox ('error message', 'file cannot be connected ')
- Case-5
- MessageBox ('error message', 'cannot connect current object ')
- Case-6
- MessageBox ('error message', 'invalid file ')
- Case-7
- MessageBox ("error prompt", "the file does not exist or has been opened ")
- Case-8
- MessageBox ("error message", "the server cannot load the selected file ")
- Case-9
- MessageBox ("error prompt", "other errors ")
- End choose
- Return
- End if
- Excelserver. workbooks. Open (ls_path, 0, false)
- // After modifying the xls file, do you need to give a warning when closing the file.
- Excelserver. application. displayalerts = false
- // Select the sheets table
- // Excelserver. activeworkbook. worksheets ("sheet2"). Select ()
- // Method 1:
- Int li_rows, li_columns
- Li_rows = excelserver. activesheet. usedrange. Rows. Count // get the total number of rows
- Li_columns = excelserver. activesheet. usedrange. Columns. Count // get the total number of rows
- // # Of columns in Excel
- Sle_2.text = trim (string (li_rows ))
- // # Of rows in Excel
- Sle_1.text = string (li_columns)
- // Lole_sheet = ole_1.application.activeworkbook.worksheets [1] // obtain the first sheet of the current work.
- For I = 1 to li_rows
- Dw_1.insertrow (0)
- For j = 1 to li_columns
- A [I, j] = string (excelserver. activesheet. cells (I, j). value)
- Dw_1.setitem (I, j, a [I, j])
- End
- End
- // Method 2: Use the clipboard
- Excelserver. activesheet. cells. Copy
- Dw_1.importclipboard (2) // The title required for data import
- Excelserver. application. activeworkbook. Close (false)
- Excelserver. application. Quit ()
- Excelserver. disconnectobject ()