Clone only content of imported chart

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1886087 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Alain Béarez 2021-02-01 00:46:25 +00:00
parent aa9ec651ea
commit e367148e09
2 changed files with 16 additions and 2 deletions

View File

@ -271,8 +271,7 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS
XSSFClientAnchor destAnchor = new XSSFClientAnchor(from, to);
destAnchor.setAnchorType(ClientAnchor.AnchorType.MOVE_AND_RESIZE);
XSSFChart destChart = createChart(destAnchor);
destChart.getCTChartSpace().set(srcChart.getCTChartSpace().copy());
destChart.getCTChart().set(destChart.getCTChartSpace().getChart());
destChart.getCTChart().set(srcChart.getCTChartSpace().getChart().copy());
return destChart;
}

View File

@ -913,6 +913,21 @@ class TestXSSFDrawing {
wb2.close();
}
@Test
void testBug63901() {
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("chartTitle_withTitle.xlsx");
XSSFSheet sheet = workbook.getSheet("Sheet1");
XSSFDrawing drawing = sheet.createDrawingPatriarch();
assert(drawing.getCharts().size() > 0);
XSSFWorkbook workbook2 = new XSSFWorkbook();
XSSFSheet sheet2 = workbook2.createSheet();
XSSFDrawing drawing2 = sheet2.createDrawingPatriarch();
drawing.getCharts().forEach(drawing2::importChart);
assertEquals(drawing.getCharts().size(), drawing2.getCharts().size());
}
private static void checkRewrite(XSSFWorkbook wb) throws IOException {
XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb);