I just started to contact PB, now want to PB programming ways to import from EXCEL file data to the database. Through the Internet to find, find the following code:
String str_savename, named s_grxh
Int excelok, li_net
Long li_count, I
Oleobject excelserver
Excelserver=create oleobject
Excelok=excelserver. Connecttonewobject (" excel. Application ")
//check the return value, in order to ensure that has successfully connected to the Excel
If excelok & lt;> 0 then
Messagebox (" message ", "the connection of EXCEL failed, please check whether installed in the computer EXCEL!" )
The return - 1
End the if
Li_net=GetFileOpenName (" select files ", str_savename, named, "like", "Excel file (*. XLS), *. XLS")
If li_net & gt; 0 then
If str_savename="" then return 1
Dw_grid. Settransobject (sqlca)
Dw_grid. Reset ()
Excelserver. Workbooks. Open (str_savename)
Excelserver. Activesheet. Cells. Copy
Li_count=dw_grid. Importclipboard ()//import data
The clipboard (" ")
Fileclose (li_net)
Excelserver. Quit ()
Excelserver. Disconnectobject ()
Destroy excelserver
Return 1
The else
Messagebox (' message ', 'does not specify import file! ')
The return - 1
End the if
First of all, the code can be used?
Second, in the above code, use a data window: dw_grid, but did not specify how to set up the DataWindows (data window). The data window should use what kind of data source? After import, and how to save to the database?
Could you give some advice?
Thank you very much!
CodePudding user response:
1. A simple look at the code, it should be feasible, copying the data to the clipboard, and then import the data from the clipboard window2. Data window using the grid format should be line, use sqlselect data source, the fields and in the excel data corresponding to the fields in the window order you ok (not according to order, the order of the SQL), after the success of the import data, called dw_1. The update () can be saved to the database
CodePudding user response:
Can be used, but there are requirements, there must be no title is the excelCodePudding user response:
If there is a drop-down window, display and storage, when import to import value displayed or stored value?CodePudding user response:
Now I am doing the same, but in my attempt, the excel import datawindow requirement is very strict, you can't appear in the excel in addition to the data line, for example, file header information, such as can not meet the requirements, the best or in rows, in bytes read, ah, very troublesome