Home > database >  Excel data import data window problem!
Excel data import data window problem!

Time:09-28

I find the code on the net, but there is always a line guide, and other import, the original excel can't open, can only be open after the reboot! Please directly! The code is as follows:
String ls_path, ls_name
Ls_path="C: \ Documents and Settings \ Administrator FLYSTONE desktop \ \ new folder (3) \ test. XLS"
Dw_1. Reset ()//clean the DW
String a [0] 1000100
The Integer I, j, li_ret

Li_ret=GetFileopenName (' select XLS, ls_path ls_name, "like", "EXCEL (*. XLS), *. XLS")
If li_ret & lt;> 1 then return

OLEObject ExcelServer
Int li_ConnectErr
ExcelServer=Create OLEObject
ExcelServer. ConnectToNewObject (" excel. Application ")

ExcelServer. Workbooks. Open (ls_path, 0, False)

ExcelServer. Application. DisplayAlerts=False

ExcelServer. ActiveSheet. Cells. Copy
Dw_1. ImportClipboard (2)//import data need title
ExcelServer. Application. Activeworkbook. Close (False)
ExcelServer. Application. The quit ()
ExcelServer. DisconnectObject ()

CodePudding user response:

You didn't destroy ExcelServer object,

This code should be ok, I also use this, specific in debugging a ha,

CodePudding user response:

Open the task manager, see execl process, you have not closed

CodePudding user response:

The building Lord try this import

String ls_execlpath, docname []

Int li_i=1
Int li_rtn

Int li_excelrow li_dwrow, li_dwcol
String ls_path
Any la_excelcell


OleObject Ole_excel, Ole_workbook

Ls_path=GetCurrentDirectory ()
Ls_path=ls_path + \ ".. "

Ole_excel=create OleObject
Ole_excel. Connecttonewobject (" excel. Application ")

//Ole_excel. Workbooks. The add ()


Li_rtn=GetFileOpenName (" please select import Excel file ", ls_execlpath, docname [], "XLS", & amp;
+ "Excel Files (*. XLS), *. XLS,", ls_path, 18)

If li_rtn=0 then
Return
End the if

Ole_excel. Workbooks. Open (ls_execlpath)
Ole_workbook=ole_excel. Worksheets (1)


Li_excelrow=2//from which lines
Li_dwcol=integer (dw_1. The describe (datawindow. Column. "count"))

Do

La_excelcell=ole_workbook. Cells (li_excelrow, 1). The value
If the trim (string (la_excelcell))='or isnull (la_excelcell) then
exit;
End the if

Li_dwrow=dw_1. Insertrow (0)

For li_i=1 to li_dwcol
Dw_1. Setitem (li_i li_dwrow, trim (string (ole_workbook. Cells (li_excelrow, li_i). The value)))
Next
Li_excelrow=li_excelrow + 1

Loop while true

Ole_excel. Quit ()
Ole_excel. Disconnectobject ()
Destroy ole_excel
Destroy ole_workbook

CodePudding user response:

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 ExcelExcel
If excelok & lt;> 0 then
Messagebox (" message ", "connection EXCEL failed, please determine whether or not fitted with 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_2. Settransobject (sqlca)
Dw_2. Reset ()
Excelserver. Workbooks. Open (str_savename)
Excelserver. Activesheet. Cells. Copy
Li_count=dw_2. Importclipboard (2)//??????? On the
The clipboard (" ")

Excelserver. Quit ()
Excelserver. Disconnectobject ()
Destroy excelserver
Return 1
The else
Messagebox (' message ', 'do not specify a file! ')
The return - 1
end if

CodePudding user response:

Is really strange, no program yesterday a try can today, and a line is, if the empty can't save, but clearly the column in the database can be null, it is how to return a responsibility??????? Experts advise!

CodePudding user response:

//line, end of line
Long ll_start_line
Ll_start_line=1
Long ll_end_line

//the last line can use below access, can also define your own
Ll_end_line=ExcelServer. ActiveSheet. UsedRange. Row - 1 + ExcelServer. ActiveSheet. UsedRange. Rows. Count

//column
Long ll_start_col
Ll_start_col=1
//the end of the column of
Long ll_end_col
//the last column can use below access, can also define your own
Ll_end_col=ExcelServer. ActiveSheet. UsedRange. Column 1 + ExcelServer. ActiveSheet. UsedRange. Columns. The Count

Dw_1. ImportClipboard (ll_start_line ll_end_line, ll_start_col, ll_end_col
)

CodePudding user response:

Mark...

CodePudding user response:

  • Related