nonstandard theme relationship ID causes crash on save

Questions and answers on how to use XLSReadWriteII 3/4/5.
Post Reply
shochberg
Posts: 17
Joined: Fri Aug 01, 2008 3:09 pm

nonstandard theme relationship ID causes crash on save

Post by shochberg »

Hi Lars,
I have some files created by another Delphi third-party component that assign a relationship ID other than rId1,2,3, etc. Those are causing exceptions when I use your component to modify and re-save the file.
I've found the problem to be that in XLSXMLExcel4.pas, you rewrite most, but not all, of the relationship IDs. But you do not rewrite the theme relationship if it exists. From procedure TXMLRelationsWorkbook.AddStd(SheetCount: integer);

if not HasType('theme') then begin
with Add('rId0') do begin
FRelType := 'theme';
FWorkbookRel := wrTheme;
FNamespace := xnsOpenXML;
FTarget := 'theme/theme1.xml';
end;
end;

Then, later, you check for all relationships in the list to have an ID starting with riD.

procedure TXMLRelationsWorkbook.Renumber;
var
i: integer;
begin
for i := 0 to Count - 1 do begin
if (Copy(Items[i].FId,1,3) = 'rId') and (StrToIntDef(Copy(Items[i].FId,4,MAXINT),-1) <> -1) then
Items[i].FId := 'rId' + IntToStr(i + 1)
else
raise Exception.Create('Unknown Id in workbook relationship');
end;
end;

Since the theme relationship still has the id specified externally, which does not start with rid, the exception is raised and the workbook cannot be saved.

Is there some reason why you choose not to rewrite the ID of the theme relationship, or if not, is this an error in your code?

Thanks.

Scott
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: nonstandard theme relationship ID causes crash on save

Post by larsa »

Hello

Version 4 has not a complete implementation of the XLSX file format. Please consider an upgrade to version 5 that works correct.
Lars Arvidsson, Axolot Data
Post Reply