R
redweek
Unregistered / Unconfirmed
GUEST, unregistred user!
从Excel中读取字符串信息时,Excel中字符串前有0,但是读出来给字符串变量后都没有0了。非常奇怪。请高手解答,因为字符串前的0很重要!!!!
procedure TForm_BankData.BitB_ExcelClick(Sender: TObject);
var
ExcelFile,SQLStr,getCode1,getCode2,getCode3:String;
sheet,EXCELApp,workbook : variant;
iRow,MaxRow,getAno:integer;
begin
try
//....创建OLE对象............
EXCELApp:=createOleObject('Excel.Application');
EXCELApp.displayAlerts:=false;
EXCELApp.ScreenUpdating:=false;
EXCELApp.WorkBooks.Add(ExcelFile);
workbook := EXCELApp.workbooks[1];
sheet:=workbook.worksheets[1];
//....取得最大行数 maxRow .........
EXCELApp.ActiveCell.SpecialCells(xlLastCell).Select;
maxRow:=EXCELApp.ActiveCell.Row; //最大行数
With Datamodul do
begin
for iRow:=4 to MaxRow do
begin
sheet.cells[iRow,10].WrapText := True;
getCode1:=sheet.cells[iRow,1]; //....下面三行出问题Excel中是'0425678',读出的getCode1内容是'425678',前面的0没有了,为什么?
getCode2:=sheet.cells[iRow,2];
//....下面三行出问题Excel中是'098765',读出的getCode1内容是'98765',前面的0没有了,为什么?
getCode3:=sheet.cells[iRow,3];
SQLStr:='Insert Into ExcelInfo(code1,code2,code3) Values('''+getCode1+''','''+getCode2+''','''+getCode3+''')';
InsertTable.Close;
InsertTable.SQL.Clear;
InsertTable.SQL.Add(SQLStr) ;
InsertTable.Prepare;
InsertTable.ExecSQL;
InsertTable.Close;
end;
//................................................
Tab_Excel.Close;
Tab_Excel.Open;
end;
finally
if not VarIsEmpty(EXCELApp) then
begin //释放对象
EXCELApp.displayAlerts:=false;
EXCELApp.ScreenUpdating:=true;
EXCELApp.quit;
end;
//.......释放对象...........
EXCELApp.displayAlerts:=false;
EXCELApp.ScreenUpdating:=true;
EXCELApp.quit;
screen.Cursor:=crDefault;
end;
end;
procedure TForm_BankData.BitB_ExcelClick(Sender: TObject);
var
ExcelFile,SQLStr,getCode1,getCode2,getCode3:String;
sheet,EXCELApp,workbook : variant;
iRow,MaxRow,getAno:integer;
begin
try
//....创建OLE对象............
EXCELApp:=createOleObject('Excel.Application');
EXCELApp.displayAlerts:=false;
EXCELApp.ScreenUpdating:=false;
EXCELApp.WorkBooks.Add(ExcelFile);
workbook := EXCELApp.workbooks[1];
sheet:=workbook.worksheets[1];
//....取得最大行数 maxRow .........
EXCELApp.ActiveCell.SpecialCells(xlLastCell).Select;
maxRow:=EXCELApp.ActiveCell.Row; //最大行数
With Datamodul do
begin
for iRow:=4 to MaxRow do
begin
sheet.cells[iRow,10].WrapText := True;
getCode1:=sheet.cells[iRow,1]; //....下面三行出问题Excel中是'0425678',读出的getCode1内容是'425678',前面的0没有了,为什么?
getCode2:=sheet.cells[iRow,2];
//....下面三行出问题Excel中是'098765',读出的getCode1内容是'98765',前面的0没有了,为什么?
getCode3:=sheet.cells[iRow,3];
SQLStr:='Insert Into ExcelInfo(code1,code2,code3) Values('''+getCode1+''','''+getCode2+''','''+getCode3+''')';
InsertTable.Close;
InsertTable.SQL.Clear;
InsertTable.SQL.Add(SQLStr) ;
InsertTable.Prepare;
InsertTable.ExecSQL;
InsertTable.Close;
end;
//................................................
Tab_Excel.Close;
Tab_Excel.Open;
end;
finally
if not VarIsEmpty(EXCELApp) then
begin //释放对象
EXCELApp.displayAlerts:=false;
EXCELApp.ScreenUpdating:=true;
EXCELApp.quit;
end;
//.......释放对象...........
EXCELApp.displayAlerts:=false;
EXCELApp.ScreenUpdating:=true;
EXCELApp.quit;
screen.Cursor:=crDefault;
end;
end;