非OLE方式写EXCEL
DGStorage为 stringgrid
try
if Length(FullExcelFileName) <= 0 then
begin
if SaveDialog1.Execute then
begin
LocalFileName := SaveDialog1.Files[0];
end else
begin
Result := False;
Exit;
end;
end else
LocalFileName := FullExcelFileName;
RowString := '';
AssignFile(ExcelFile, LocalFileName);
Rewrite(ExcelFile);
try
Write(ExcelFile, RowString);
for i := 0 to DGStorage.RowCount - 1 do
begin
for j := 0 to DGStorage.ColCount - 1 do
begin
if j > 0 then
begin
RowString := RowString + #9 + DGStorage.cells[j, i];
end else
begin
RowString := DGStorage.cells[j, i]; ;
end;
end;
RowString := #13 + #10 + RowString;
Write(ExcelFile, RowString);
RowString := '';
end;
finally
CloseFile(ExcelFile);
end;
Result := True;
except
Result := False;
end;
RowString'11 '#9'1113111112101245 '#9'上海金杨鞋柜 '#9'1 '#9'2013-08-04 '时 写入EXCEL中的第二个字符由1113111112101245变成了
RowString := RowString + #9 + DGStorage.cells[j, i]+'|';
xlsApp.ActiveWorkbook.ActiveSheet.cells[j,1].NumberFormatLocal:='G/通用格式';
xlsApp.ActiveWorkbook.ActiveSheet.cells[j,2].NumberFormatLocal:='@';