FPSpreadsheet: Prevent Excel read error when a chart contains no series.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9444 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2024-09-15 22:25:32 +00:00
parent dc76d5d993
commit 3d203a2dc4
2 changed files with 12 additions and 11 deletions

View File

@ -6618,6 +6618,12 @@ procedure TsSpreadOOXMLWriter.WriteDrawings(AWorksheet: TsBasicWorksheet);
sheet: TsWorksheet;
guid: TGUID;
begin
// When a chart contains no series Excel writes a completely different
// node for the chart, otherwise reading of the file crashes.
// --> Do not write an empty chart in our way at all.
if AChart.Series.Count = 0 then
exit;
r1 := AChart.Row;
c1 := AChart.Col;
rOffs1 := AChart.OffsetY;

View File

@ -4270,13 +4270,11 @@ procedure TsSpreadOOXMLChartWriter.WriteChartPlotAreaNode(AStream: TStream;
var
indent: String;
i: Integer;
ser: TsChartSeries;
xAxKind: String = 'c:catAx';
yAxKind: String = 'c:valAx';
x2AxKind: String;
xAxKind, yAxKind, x2AxKind: String;
hasSecondaryAxis: Boolean = false;
begin
indent := DupeString(' ', AIndent);
FAxisID[caaBottom] := Random(MaxInt);
FAxisID[caaLeft] := Random(MaxInt);
FAxisID[caaRight] := Random(MaxInt);
@ -4287,14 +4285,11 @@ begin
indent + '<c:plotArea>' + LE
);
if AChart.Series.Count > 0 then
begin
// Write series attached to primary y axis
WriteChartSeries(AStream, AIndent + 2, AChart, calPrimary, xAxKind);
// Write series attached to primary y axis
WriteChartSeries(AStream, AIndent + 2, AChart, calPrimary, xAxKind);
// Write series attached to secondary y axis
hasSecondaryAxis := WriteChartSeries(AStream, AIndent + 2, AChart, calSecondary, x2AxKind);
end;
// Write series attached to secondary y axis
hasSecondaryAxis := WriteChartSeries(AStream, AIndent + 2, AChart, calSecondary, x2AxKind);
// Write the x and y axes. No axes for pie series and related.
if not (AChart.GetChartType in [ctPie, ctRing]) then