Josip Miller
Josip Miller

Reputation: 1

Excel 2007 gets CSV file wrong?

I am using Delphi 7 to generate CSV file from data acquired from COM port. Now, this seems to work OK since any other spreadsheet software reads generated file properly (Open Office and Libre Office spreadshhet software, for instance). Excel 2007 does the following. Instead of these two column values:

1.976139e-2<TAB>22.98027

i got these two column values:

1.98E+04<TAB>2.298.027

Note that generated file opened in any text editor (Notepad++ for instance) has proper values. What could be the problem here ?

Thanks,

Josip

Upvotes: 0

Views: 311

Answers (2)

bummi
bummi

Reputation: 27377

If the setting in Delphi do not fit your needs you could change them before loading the CSV. But you should make sure to reset them afterwards.

var
  Excel, WorkBook: Variant;
  KeepDecimalSeparator, KeepThousandsSeparator: String;
  KeepUseSystem: Boolean;
begin
  Excel := CreateOleObject('Excel.Application');
  Excel.Visible := true;
  try
    KeepDecimalSeparator := Excel.DecimalSeparator;
    KeepThousandsSeparator := Excel.ThousandsSeparator;
    KeepUseSystem := Excel.UseSystemSeparators;
    Excel.DecimalSeparator := '.';
    Excel.ThousandsSeparator := ',';
    Excel.UseSystemSeparators := false;
    WorkBook := Excel.WorkBooks.Open('C:\Temp\1.csv');
  finally
    Excel.DecimalSeparator := KeepDecimalSeparator;
    Excel.ThousandsSeparator := KeepThousandsSeparator;
    Excel.UseSystemSeparators := KeepUseSystem;
  end;
end;

Upvotes: 3

kot-da-vinci
kot-da-vinci

Reputation: 1204

Try to use quotes.

"1.976139e-2"<TAB>"22.98027"

Upvotes: -2

Related Questions