【发布时间】:2013-06-09 02:20:59
【问题描述】:
我的项目有问题。 我想将我在 dbgrid 中的数据导出到 ole 中。
当我将包含时间的字段(格式短时间 hh:mm)导出到 excel 时,它在 excel 中显示为长日期格式(MM/dd/yyyy h:mm:ss AM/PM)。
我想要的是它仍然在 excel 中显示短时格式 (hh:mm)
我在编码中将数字格式设置为 hh:mm,但仍以长日期格式显示。
ADOQuery1.First;
x:=1;
while not ADOQuery1.Eof do
begin
for i:=0 to DBGrid1.FieldCount-1 do
begin
XlSheet.cells[2+x,i+1].value:=DBGrid1.Fields[i].Text;
XlSheet.cells[2+x,i+1].Borders.Weight:=xlThin;
XlSheet.cells[2+x,i+1].Font.Size:=10;
end;
ADOQuery1.Next;
Inc(x);
end;
XlSheet.Columns[8].NumberFormat:='hh:mm;@';
我正在使用数据库访问,该字段的数据类型是日期/时间和短时间格式。 对不起,我的英语不好。 谢谢你。 :D
【问题讨论】:
-
检查日期列实际上是#8 而不是别的。实际上这是相当脆弱的 - DBgrid 的小重组,它不会再工作了。 /// 尝试从格式中删除“;@”。
标签: excel delphi time export ole