diff --git a/components/fpspreadsheet/xlsxooxml.pas b/components/fpspreadsheet/xlsxooxml.pas index 412cab585..8d8965d2f 100755 --- a/components/fpspreadsheet/xlsxooxml.pas +++ b/components/fpspreadsheet/xlsxooxml.pas @@ -231,13 +231,14 @@ const { OOXML mime types constants } {%H-}MIME_XML = 'application/xml'; MIME_RELS = 'application/vnd.openxmlformats-package.relationships+xml'; - MIME_SPREADML = 'application/vnd.openxmlformats-officedocument.spreadsheetml'; + MIME_OFFICEDOCUMENT = 'application/vnd.openxmlformats-officedocument'; + MIME_SPREADML = MIME_OFFICEDOCUMENT + '.spreadsheetml'; MIME_SHEET = MIME_SPREADML + '.sheet.main+xml'; MIME_WORKSHEET = MIME_SPREADML + '.worksheet+xml'; MIME_STYLES = MIME_SPREADML + '.styles+xml'; MIME_STRINGS = MIME_SPREADML + '.sharedStrings+xml'; MIME_COMMENTS = MIME_SPREADML + '.comments+xml'; - MIME_VMLDRAWING = MIME_SPREADML + '.vmlDrawing'; + MIME_VMLDRAWING = MIME_OFFICEDOCUMENT + '.vmlDrawing'; LAST_PALETTE_COLOR = $3F; // 63 @@ -1866,9 +1867,8 @@ begin ''+ ''+ // this entire node could be omitted, but then Excel uses some default font out of control ''+ -// ''+ - ''+ // it could be that color index 81 does not exist in fps files --> use rgb instead - ''+ // it is not harmful to Excel if "Tahoma" does not exist. + ''+ // It could be that color index 81 does not exist in fps files --> use rgb instead + ''+ // It is not harmful to Excel if the font does not exist. ''+ ''+ '' + comment + '' + @@ -2349,10 +2349,9 @@ begin 'xmlns:x="urn:schemas-microsoft-com:office:excel">' + LineEnding); // My xml viewer does not format vml files property --> format in code. AppendToStream(FSVmlDrawings[FCurSheetNum], - ' '+LineEnding+{Format(} + ' ' + LineEnding + ' ' + LineEnding + // "data" is a comma-separated list with the ids of groups of 1024 comments -- really? -// ' ', [FCurSheetNum+1]) + LineEnding + ' ' + LineEnding); AppendToStream(FSVmlDrawings[FCurSheetNum], ' '+LineEnding+ @@ -2427,6 +2426,7 @@ begin AppendToStream(FSSheetRels[FCurSheetNum], Format( '', [SCHEMAS_DRAWINGS, FCurSheetNum+1])); + // Footer AppendToStream(FSSheetRels[FCurSheetNum], ''); @@ -2495,24 +2495,27 @@ end; procedure TsSpreadOOXMLWriter.WriteContent; var - i: Integer; + i, counter: Integer; begin { --- WorkbookRels --- { Workbook relations - Mark relation to all sheets } + counter := 0; AppendToStream(FSWorkbookRels, XML_HEADER); AppendToStream(FSWorkbookRels, ''); - AppendToStream(FSWorkbookRels, - ''); - AppendToStream(FSWorkbookRels, - ''); - - for i:=1 to Workbook.GetWorksheetCount do + while counter <= Workbook.GetWorksheetCount do begin + inc(counter); AppendToStream(FSWorkbookRels, Format( '', - [SCHEMAS_WORKSHEET, i, i+2])); // +2 because of styles.xml and sharedStrings.xml - + [SCHEMAS_WORKSHEET, counter, counter])); + end; + AppendToStream(FSWorkbookRels, Format( + '', + [counter+1, SCHEMAS_STYLES])); + AppendToStream(FSWorkbookRels, Format( + '', + [counter+2, SCHEMAS_STRINGS])); AppendToStream(FSWorkbookRels, ''); @@ -2532,9 +2535,10 @@ begin ''); AppendToStream(FSWorkbook, ''); - for i:=1 to Workbook.GetWorksheetCount do + for counter:=1 to Workbook.GetWorksheetCount do AppendToStream(FSWorkbook, Format( - '', [Workbook.GetWorksheetByIndex(i-1).Name, i, i+2])); + '', + [Workbook.GetWorksheetByIndex(counter-1).Name, counter, counter])); AppendToStream(FSWorkbook, ''); AppendToStream(FSWorkbook, @@ -2825,16 +2829,19 @@ begin end; for i:=0 to High(FSComments) do begin + if FSComments[i] = nil then continue; FSComments[i].Position := 0; FZip.Entries.AddFileEntry(FSComments[i], OOXML_PATH_XL + Format('comments%d.xml', [i+1])); end; for i:=0 to High(FSSheetRels) do begin + if FSSheetRels[i] = nil then continue; FSSheetRels[i].Position := 0; FZip.Entries.AddFileEntry(FSSheetRels[i], OOXML_PATH_XL_WORKSHEETS_RELS + Format('sheet%d.xml.rels', [i+1])); end; for i:=0 to High(FSVmlDrawings) do begin + if FSVmlDrawings[i] = nil then continue; FSVmlDrawings[i].Position := 0; FZip.Entries.AddFileEntry(FSVmlDrawings[i], OOXML_PATH_XL_DRAWINGS + Format('vmlDrawing%d.vml', [i+1])); end;