Exception raised when setting PrintTitles after sheet rename

Questions and answers on how to use XLSReadWriteII 5.
Post Reply
KenWhite
Posts: 13
Joined: Mon Jan 03, 2005 8:23 pm
Contact:

Exception raised when setting PrintTitles after sheet rename

Post by KenWhite »

I'm using XLSReadWriteII5 v5.20.69.

I'm getting an exception when I try to set PrintTitles after the sheet is renamed. It works fine if I set PrintTitles first. Here's an example that demonstrates:

Code: Select all

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils, XLSReadWriteII5;

var
  XLS: TXLSReadWriteII5;
  i: Integer;
begin
  XLS := TXLSReadWriteII5.Create(nil);
  try
    // Just to provide a headings row
    for i := 0 to 3 do
      XLS[0].AsString[i, 0] := Format('Col %d', [i]);

    XLS[0].FillRandom('A3:D12', 1000);

    // Titles first, then setting new sheet name works
    // XLS[0].PrintSettings.PrintTitles(0, 255, 0, 2);
    // XLS[0].Name := 'New sheet';

    // Setting new sheet name first, then title raises exception Unknown sheet name "sheet"
    XLS[0].Name := 'New sheet';
    XLS[0].PrintSettings.PrintTitles(0, 255, 0, 2);

    XLS.SaveToFile('C:\Temp\TitleTest.xlsx');
    try
      { TODO -oUser -cConsole Main : Insert code here }
    except
      on E:Exception do
        Writeln(E.Classname, ': ', E.Message);
    end;
  finally
    XLS.Free;
  end;
end.
The exception is happening in XLSEncodeFmla5 in the call to GetSheetIndex (inside TXLSFormulaEncoder.AddCellRef), but I can't seem to figure out why. I debugged it as far as the call to Compile (from TXLSName.SetDefinition), but admit I got lost from that point on.

Does setting PrintTitles require that it's done before changing the sheet name?
Ken
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Exception raised when setting PrintTitles after sheet rename

Post by larsa »

Hello

The problem is when there is spaces in the sheet name. This is fixed in update 5.20.70
Lars Arvidsson, Axolot Data
Post Reply