Exception raised when setting PrintTitles after sheet rename
Posted: Tue Feb 02, 2016 4:11 pm
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:
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?
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.
Does setting PrintTitles require that it's done before changing the sheet name?