我这个代码是导出到文本文件中的,你改一下就行了,
procedure TL_DataFormatImportF.Excel2Txt(SrcFileName: string; DestFileName: string; WorkSheetIdx,
BeginRow, EndRow, BeginCol, EndCol: integer);
var
ExcelApp: Variant;
ExCelSheet: Variant;
F: TextFile;
TmpStr: Ansistring;
i, j: integer;
begin
try
//--
try
ExcelApp := CreateOleObject('Excel.Application'); //创建EXCEL对象
except
Application.MessageBox('没有安装EXCEL!', '提示', Mb_Ok or Mb_IconError);
Exit;
end;
ExcelApp.WorkBooks.Open(SrcFileName); //打开EXCEL文件
ExcelApp.WorkSheets[WorkSheetIdx].Activate; //当前活动的WORKSHEET
ExcelSheet := ExcelApp.WorkSheets[WorkSheetIdx]; //当前活动SHEET
ExcelApp.Visible := False; //不可见
//--
for i := BeginRow to EndRow do //开始行和结束行
begin
TmpStr := '';
for j := BeginCol to EndCol do
begin
if j = EndCol then //最后一列
begin
try
TmpStr := TmpStr + string(ExcelSheet.Cells.Item[i, j]);
except
end;
end
else //不是最后一列要加列分隔符
begin
try
TmpStr := TmpStr + string(ExcelSheet.Cells.Item[i, j]) + #9;
except
end;
end;
end; // END FOR J
TmpStr := StringReplace(TmpStr, #13#10, '', [rfReplaceAll]);
TmpStr := StringReplace(TmpStr, '''''', '', [rfReplaceAll]);
Writeln(F, TmpStr); //文本文件写一行数据
Gauge6.Progress := i;
end; //END FOR I
finally
Screen.Cursor := crDefault;
ExcelApp.Caption := '';
ExcelApp.WorkBooks.Close;
ExcelApp.Quit; //关闭 EXCEL
end;
end;