Save changes, without changes!?

Questions and answers on how to use XLSReadWriteII 3/4/5.
Post Reply
SirRobert
Posts: 2
Joined: Fri Dec 22, 2006 9:49 pm

Save changes, without changes!?

Post by SirRobert »

Hello,

i create a simple xls file with:

Code: Select all

var
        xls : TXLSReadWriteII2;
        FS : TFileStream;
begin
 try
        XLS := TXLSReadWriteII2.Create(NIL);
        XLS.Version := xvExcel97;
        XLS.Sheet[0].AsInteger[0,0] := 1;
        XLS.Sheet[0].AsInteger[0,1] := 2;
        XLS.Sheet[0].AsFormula[0,2] := 'SUM(A1:A2)';
        FS := TFileStream.Create('C:\~temp.xls', fmCreate);
        XLS.WriteToStream(FS);
 finally
        FS.Free;
        XLS.Free;
 end;
end;
So, if i open this file and close it again (WITHOUT any changes), Excel ask me: Save the changes?

WHY??

Thanks and sorry for my english! :shock:

Robert

(XLSReadWriteII2 Ver. 3.00.07, Delphi 6 Prof., Excel 2000)
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Post by larsa »

Hello

Because the formula(s) are calculated when the file is opened, and hence the file is changed. If you don't want this message, you can either:

1. Tell excel not to calculate the formulas (Please not that all formulas will then have a result of zero).

2. Calculate them with XLSReadWriteII.

Example:

Code: Select all

  XLS.Sheet[0].AsInteger[0,0] := 1;
  XLS.Sheet[0].AsInteger[0,1] := 2;
  XLS.Sheet[0].AsFormula[0,2] := 'SUM(A1:A2)';
  // Tell excel not to calculate formulas
  XLS.Sheet[0].RecalcFormulas := False;
  // Do the calculation here
  XLS.Calculate;
Lars Arvidsson
SirRobert
Posts: 2
Joined: Fri Dec 22, 2006 9:49 pm

Post by SirRobert »

COOL, IT WORKS!!! :D

Thanks!
Post Reply