I'd like to copy a TXLSFile that is in memory and then in the new version delete all but the active sheet. I thought this would be easy but I've run into a problem.
Here's a simplified version of the code (see below). The error message is "There are not visible sheets on the file". However, the sheet count is shown as 3.
Is this a bug? Here's a link to the small demo project: https://goo.gl/3wgnVp
procedure TForm1.Button1Click(Sender: TObject);
var
xls: TXLSFile;
xlsErrors: TXLSFile;
s: TMemoryStream;
i, j: integer;
LastBad: integer;
RowStart, RowCount: integer;
begin
//-- Load File
xls := TXlsFile.Create;
xls.Open('C:\Users\Steve Maughan\Documents\Embarcadero\Studio\Projects\Delete Sheets\Book1.xlsx');
xls.ActiveSheet := 2;
//-- Duplicate the workbook
xlsErrors := TXLSFile.Create;
s := TMemoryStream.Create;
xls.Save(s);
s.Position := 0;
xlsErrors.Open(s);
s.Free;
//-- Delete all the other worksheets
xlsErrors.ActiveSheet := xls.ActiveSheet;
i := xlsErrors.SheetCount;
j := xls.ActiveSheet;
while xlsErrors.SheetCount > 1 do
begin
if (i <> j) then
xlsErrors.DeleteSheet(i); // <----ERROR ("There are not visible sheets on the file")
dec(i);
end;
//-- Export
xlsErrors.Save('ErrorFile.xlsx');
xlsErrors.Free;
end;