F
fuxin198311
Unregistered / Unconfirmed
GUEST, unregistred user!
把dbgrideh的数据导出excel 为什么我导出字段显示的是英文呢 而不是dbgrideh中的中文字段 怎样让导出的字段显示的是中文的 还有汇总的数据导不出 代码是这样的
procedure Tyaopinzd.SpeedButton6Click(Sender: TObject);
var i, row, column:integer;
begin
try
ExcelApplication1.Connect;
except
MessageDlg('Excel may not be installed', mtError, [mbOk], 0);
Abort;
End;
ExcelApplication1.Visible[0] := true;
ExcelApplication1.Caption := 'Excel';
ExcelApplication1.Workbooks.Add(Null, 0);
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1] as _Worksheet);
row:=1;
try
for i:=0 to adoquery1.FieldCount-1 do
begin
ExcelWorksheet1.Cells.Item[1,i+1]:=adoquery1.Fields.DisplayName;
end;
row:=row+1;
adoquery1.First;
while not adoquery1.Eof do
begin
column:=1;
for i:=1 to adoquery1.FieldCount do
begin
ExcelWorksheet1.Cells.Item[row,column]:=adoquery1.Fields[i-1].AsString;
column:=column+1;
end;
adoquery1.Next;
row:=row+1;
end;
application.MessageBox('导出成功','提示',64);
except
application.MessageBox('发生错误,'提示',mb_iconstop);
Abort;
end;
ExcelApplication1.Disconnect;
ExcelWorkbook1.Disconnect;
ExcelWorksheet1.Disconnect;
end;
procedure Tyaopinzd.SpeedButton6Click(Sender: TObject);
var i, row, column:integer;
begin
try
ExcelApplication1.Connect;
except
MessageDlg('Excel may not be installed', mtError, [mbOk], 0);
Abort;
End;
ExcelApplication1.Visible[0] := true;
ExcelApplication1.Caption := 'Excel';
ExcelApplication1.Workbooks.Add(Null, 0);
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1] as _Worksheet);
row:=1;
try
for i:=0 to adoquery1.FieldCount-1 do
begin
ExcelWorksheet1.Cells.Item[1,i+1]:=adoquery1.Fields.DisplayName;
end;
row:=row+1;
adoquery1.First;
while not adoquery1.Eof do
begin
column:=1;
for i:=1 to adoquery1.FieldCount do
begin
ExcelWorksheet1.Cells.Item[row,column]:=adoquery1.Fields[i-1].AsString;
column:=column+1;
end;
adoquery1.Next;
row:=row+1;
end;
application.MessageBox('导出成功','提示',64);
except
application.MessageBox('发生错误,'提示',mb_iconstop);
Abort;
end;
ExcelApplication1.Disconnect;
ExcelWorkbook1.Disconnect;
ExcelWorksheet1.Disconnect;
end;