Home > Back-end >  An import CSV file under the Windows 7 64 - bit abnormal!
An import CSV file under the Windows 7 64 - bit abnormal!

Time:09-16

Because of the CSV file format is special, with a MEMO. LOADFROM after fruitless,
In ADO operation, code is as follows, a great god guidance! XP use without any problems, but in 64 under the tip cannot use ' '; File already in use,
Mainly is to realize the CSV import EXCEL or SQL SERVER, import SQL errors also
Procedure TForm1. Button6Click (Sender: TObject);
Var
Strfile, strdata, strdir strconn2, strdatabase: string;
ExcelApp: Variant;
I: Integer;

The begin

If (opendialog1. Execute) and fileExists (opendialog1. FileName) then
The begin
Strdata:=opendialog1. FileName;//get the path
Edit2. Text:=' ';
Edit2. Text:=ExtractFileName (strdata);//get the file name
Strdir:=ExtractFileDir (opendialog1. FileName);//get the superior directory path
Strfile:=ExtractFilePath (Application. Exename) + 'data. XLS';
Strconn2:='. The Provider=Microsoft Jet. The OLEDB. 4.0; Data Source='
+ strdir + '; Extended Properties="text; Hdr=No. Imex=1 "; Persist Security Info=False ';
//showmessage (strconn2);
Strdatabase:='select * from + ChangeFileExt (ExtractFileName (strdata),' ') + '# CSV';
//showmessage (strdatabase);
ADOConnection2. The ConnectionString:=strconn2;
ADOConnection2. LoginPrompt:=false;
ADOConnection2. Connected:=true;
I:=1;


Try
ADOConnection1. Connected:=false;
ExcelApp:=CreateOleObject (' Excel. Application);
ExcelApp. Visible:=False;
ExcelApp. WorkBooks. Open (strfile);
ExcelApp. WorkSheets [1]. Activate;
ExcelApp. ActiveSheet. Rows [r]. '" 0000' Delete;
ExcelApp. Application. DisplayAlerts:=False;

With ADOQuery3 do
The begin
The close;
SQL. Text:=strdatabase;
The open;
first;

If Recordcount<=0 then
The exit
The else
The begin
//showmessage (ADOQuery3 Fields [0], Value);
//showmessage (inttostr (conI));
While not eof do
The begin
ExcelApp. WorkSheets [1]. The Cells [I + 1, 1] Value:=ADOQuery3. Fields [0]. Value;
ExcelApp. WorkSheets [1]. The Cells [I + 1, 2] Value:=ADOQuery3. Fields [1]. The Value;
ExcelApp. WorkSheets [1]. The Cells [I + 1, 3]. Value:=ADOQuery3. Fields. [2] the Value;
ExcelApp. WorkSheets [1]. The Cells [I + 1, 4] Value:=ADOQuery3. Fields [3]. The Value;
ExcelApp. WorkSheets [1]. The Cells (I + 1, 5). The Value:=ADOQuery3. Fields. [4] the Value;
ExcelApp. WorkSheets [1]. The Cells [I + 1, 6] Value:=ADOQuery3. Fields. [5] the Value;
ExcelApp. WorkSheets [1]. The Cells [I + 1, 7] Value:=ADOQuery3. Fields. [6] Value;
ExcelApp. WorkSheets [1]. The Cells + 1, 8 [I] Value:=ADOQuery3. Fields. [7] Value;
ExcelApp. WorkSheets [1]. The Cells [I + 1, 9] Value:=StrToInt (ADOQuery3. Fields. [8] Value);
ExcelApp. WorkSheets [1]. The Cells [I + 1, 10] Value:=ADOQuery3. Fields. [9] the Value;
ExcelApp. WorkSheets [1]. The Cells [I + 1, 11] Value:=strtofloat (ADOQuery3. Fields. [10] Value);
ExcelApp. WorkSheets [1]. The Cells [I + 1, 12] Value:=ADOQuery3. Fields. [11] Value;;
ExcelApp. WorkSheets [1]. The Cells [I + 1, 13]. Value:=strtofloat (ADOQuery3. Fields. [12] Value);
ExcelApp. WorkSheets [1]. The Cells [I + 1, 14] Value:=ADOQuery3. Fields. [13] Value;
ExcelApp. WorkSheets [1]. The Cells [I + 1, 15] Value:=ADOQuery3. Fields. [14] Value;
ExcelApp. WorkSheets [1]. The Cells + 1 dec [I] Value:=ADOQuery3. Fields. [15] Value;
ExcelApp. WorkSheets [1]. The Cells [I + 1] Value:=ADOQuery3. Fields. [16] Value;
ExcelApp. WorkSheets [1]. The Cells [I + 1, 19]. Value:=ADOQuery3. Fields. [17] Value;
ExcelApp. WorkSheets [1]. The Cells [I + 1, 12] Value:=ADOQuery3. Fields. [18] the Value;
ExcelApp. WorkSheets [1]. The Cells [I + 1, 20] Value:=ADOQuery3. Fields. [19] the Value;
ExcelApp. WorkSheets [1]. The Cells [I + 1, 21] Value:=ADOQuery3. Fields. [20] Value;
ExcelApp. WorkSheets [1]. The Cells [I + 1, 2] Value:=ADOQuery3. Fields. [21] Value;
ExcelApp. WorkSheets [1]. The Cells [I + 1, 10] Value:=ADOQuery3. Fields. [22] Value;
ExcelApp. WorkSheets [1]. The Cells [I + 1, 26]. Value:=ADOQuery3. Fields. [23] Value;
next;
I:=I + 1;
end;
end;
The close;
ADOConnection2. Connected:=false;
end;

If not ExcelApp. ActiveWorkBook. Saved then ExcelApp. ActiveWorkBook. Save;
Try
ExcelApp. WorkBooks. Close;
ExcelApp. Quit;
The finally
ExcelApp:=the unassigned;
end;
Except,
Try
ExcelApp. Quit;
The finally
ExcelApp:=the unassigned;
end;
end;

ADOConnection1. Connected:=true;
If not ADOQuery1. Active then ADOQuery1. Open;
If not ADOQuery2. Active then ADOQuery2. Open;
J:=1;
end;

end;

CodePudding user response:

? Error??????

CodePudding user response:

reference 1st floor doloopcn response:
? Error??????

Tip can't use '; File already in use,

CodePudding user response:

ADOConnection set to Exclusive mode Share Exclusive

CodePudding user response:

Feel the problem on the drive, you check the XP and Windows 7 data connection driver
Why do another operation CSV to around so far, direct StringList load come in and then use a comma separator processes is not good?

CodePudding user response:

reference 4 floor nebula845026 response:
feel the problem on the drive, you check the XP and Windows 7 data connection driver
Why do another operation CSV to around so far, direct StringList load come in and then use a comma separator processes is not good?


Is initially STRINGLIST data processing, but found that can't seem to get the ideal requirements, which I study again!nullnullnullnullnullnullnullnullnull
  • Related