使用
ExcelWorkSheet1.Cells.Item[i,j]:=Mydata.Fields[j].assting;
把数据导出到Excel时,数据库中有一个字段比较大为Varcha2(30),导出后Excel中的此字段数据后几为全部变成了'0',例如字段值为415265256000000000200202020101,则Excle中为415265256000000000200202000000.
ExcelWorkSheet1.Cells.Item[i,j]:=Mydata.Fields[j].assting;
把数据导出到Excel时,数据库中有一个字段比较大为Varcha2(30),导出后Excel中的此字段数据后几为全部变成了'0',例如字段值为415265256000000000200202020101,则Excle中为415265256000000000200202000000.
var
i,row:integer;
begin
if SaveDialog1.Execute then
begin
Screen.Cursor:=crHourGlass;
ExcelApplication1.Connect;
ExcelApplication1.Workbooks.Add(Null,0);
ExcelWorkBook1.ConnectTo(ExcelApplication1.Workbooks[1]);
ExcelWorkSheet1.ConnectTo(ExcelWorkBook1.Sheets[1] as _WorkSheet);
if not adoQuery1.Active then
begin
adoQuery1.Open;
end;
for i:=0 to adoQuery1.Fields.Count-1 do
ExcelWOrkSheet1.Cells.Item[1,i+1]:=adoQuery1.Fields[i].FieldName;
row:=2;
while not adoQuery1.Eof do
begin
for i:=0 to adoQuery1.Fields.Count-1 do
ExcelWOrkSheet1.Cells.Item[row-1,i+1]:=adoQuery1.Fields[i].AsString;
row:=row+1;
adoQuery1.Next;
end;
ExcelWorkBook1.SaveCopyAs(SaveDialog1.FileName);
ExcelWOrkBook1.Close(false); //excel关闭对话框
ExcelApplication1.Disconnect;//断开,
ExcelApplication1.Quit;//退出
Screen.Cursor:=crDefault;
Application.MessageBox('文件成功导出!','信息提示',0);
end;
adoquery1.Close;
'A'+table1.fields[0].asstring;
这样就成文本型了,