Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 12 additions & 19 deletions src/examples/src/org/apache/poi/xslf/usermodel/BarChartDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public static void main(String[] args) throws Exception {
return;
}

BufferedReader modelReader = new BufferedReader(new FileReader(args[1]));
XMLSlideShow pptx = null;
try {
try (FileInputStream argIS = new FileInputStream(args[0]);
BufferedReader modelReader = new BufferedReader(new FileReader(args[1]))) {

String chartTitle = modelReader.readLine(); // first line is chart title

// Category Axis Data
Expand All @@ -76,25 +76,18 @@ public static void main(String[] args) throws Exception {
String[] categories = listCategories.toArray(new String[listCategories.size()]);
Double[] values = listValues.toArray(new Double[listValues.size()]);

pptx = new XMLSlideShow(new FileInputStream(args[0]));
XSLFSlide slide = pptx.getSlides().get(0);
setBarData(findChart(slide), chartTitle, categories, values);
try (XMLSlideShow pptx = new XMLSlideShow(argIS)) {
XSLFSlide slide = pptx.getSlides().get(0);
setBarData(findChart(slide), chartTitle, categories, values);

XSLFChart chart = findChart(pptx.createSlide().importContent(slide));
setColumnData(chart, "Column variant");
XSLFChart chart = findChart(pptx.createSlide().importContent(slide));
setColumnData(chart, "Column variant");

// save the result
OutputStream out = new FileOutputStream("bar-chart-demo-output.pptx");
try {
pptx.write(out);
} finally {
out.close();
}
} finally {
if (pptx != null) {
pptx.close();
// save the result
try (OutputStream out = new FileOutputStream("bar-chart-demo-output.pptx")) {
pptx.write(out);
}
}
modelReader.close();
}
}

Expand Down
13 changes: 7 additions & 6 deletions src/examples/src/org/apache/poi/xslf/usermodel/PieChartDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ public static void main(String[] args) throws Exception {
return;
}

try (BufferedReader modelReader = new BufferedReader(new FileReader(args[1]))) {
try (FileInputStream argIS = new FileInputStream(args[0]);
BufferedReader modelReader = new BufferedReader(new FileReader(args[1]))) {
String chartTitle = modelReader.readLine(); // first line is chart title

try (XMLSlideShow pptx = new XMLSlideShow(new FileInputStream(args[0]))) {
try (XMLSlideShow pptx = new XMLSlideShow(argIS)) {
XSLFSlide slide = pptx.getSlides().get(0);

// find chart in the slide
Expand All @@ -70,17 +71,17 @@ public static void main(String[] args) throws Exception {
if(chart == null) {
throw new IllegalStateException("chart not found in the template");
}

// Series Text
List<XDDFChartData> series = chart.getChartSeries();
XDDFPieChartData pie = (XDDFPieChartData) series.get(0);

// Category Axis Data
List<String> listCategories = new ArrayList<String>(3);

// Values
List<Double> listValues = new ArrayList<Double>(3);

// set model
String ln;
while((ln = modelReader.readLine()) != null){
Expand Down
104 changes: 104 additions & 0 deletions src/examples/src/org/apache/poi/xssf/usermodel/examples/BarChart.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.xssf.usermodel.examples;

import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xddf.usermodel.PresetColor;
import org.apache.poi.xddf.usermodel.XDDFColor;
import org.apache.poi.xddf.usermodel.XDDFShapeProperties;
import org.apache.poi.xddf.usermodel.XDDFSolidFillProperties;
import org.apache.poi.xddf.usermodel.chart.AxisCrosses;
import org.apache.poi.xddf.usermodel.chart.AxisPosition;
import org.apache.poi.xddf.usermodel.chart.ChartTypes;
import org.apache.poi.xddf.usermodel.chart.LegendPosition;
import org.apache.poi.xddf.usermodel.chart.XDDFCategoryAxis;
import org.apache.poi.xddf.usermodel.chart.XDDFChartData;
import org.apache.poi.xddf.usermodel.chart.XDDFChartLegend;
import org.apache.poi.xddf.usermodel.chart.XDDFDataSource;
import org.apache.poi.xddf.usermodel.chart.XDDFDataSourcesFactory;
import org.apache.poi.xddf.usermodel.chart.XDDFNumericalDataSource;
import org.apache.poi.xddf.usermodel.chart.XDDFValueAxis;
import org.apache.poi.xssf.usermodel.XSSFChart;
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
import org.apache.poi.xssf.usermodel.XSSFDrawing;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

/**
* Line chart example.
*/
public class BarChart {

public static void main(String[] args) throws IOException {
try (XSSFWorkbook wb = new XSSFWorkbook()) {
XSSFSheet sheet = wb.createSheet("barchart");
final int NUM_OF_ROWS = 3;
final int NUM_OF_COLUMNS = 10;

// Create a row and put some cells in it. Rows are 0 based.
Row row;
Cell cell;
for (int rowIndex = 0; rowIndex < NUM_OF_ROWS; rowIndex++) {
row = sheet.createRow((short) rowIndex);
for (int colIndex = 0; colIndex < NUM_OF_COLUMNS; colIndex++) {
cell = row.createCell((short) colIndex);
cell.setCellValue(colIndex * (rowIndex + 1));
}
}

XSSFDrawing drawing = sheet.createDrawingPatriarch();
XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 5, 10, 15);

XSSFChart chart = drawing.createChart(anchor);
XDDFChartLegend legend = chart.getOrAddLegend();
legend.setPosition(LegendPosition.TOP_RIGHT);

// Use a category axis for the bottom axis.
XDDFCategoryAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);
leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);

XDDFDataSource<Double> xs = XDDFDataSourcesFactory.fromNumericCellRange(sheet, new CellRangeAddress(0, 0, 0, NUM_OF_COLUMNS - 1));
XDDFNumericalDataSource<Double> ys1 = XDDFDataSourcesFactory.fromNumericCellRange(sheet, new CellRangeAddress(1, 1, 0, NUM_OF_COLUMNS - 1));
XDDFNumericalDataSource<Double> ys2 = XDDFDataSourcesFactory.fromNumericCellRange(sheet, new CellRangeAddress(2, 2, 0, NUM_OF_COLUMNS - 1));

XDDFChartData data = chart.createData(ChartTypes.BAR, bottomAxis, leftAxis);
data.addSeries(xs, ys1);
data.addSeries(xs, ys2);
chart.plot(data);

XDDFSolidFillProperties fill = new XDDFSolidFillProperties(XDDFColor.from(PresetColor.CHARTREUSE));
XDDFChartData.Series firstSeries = data.getSeries().get(0);
XDDFShapeProperties properties = firstSeries.getShapeProperties();
if (properties == null) {
properties = new XDDFShapeProperties();
}
properties.setFillProperties(fill);
firstSeries.setShapeProperties(properties);

// Write the output to a file
try (FileOutputStream fileOut = new FileOutputStream("ooxml-bar-chart.xlsx")) {
wb.write(fileOut);
}
}
}
}
46 changes: 46 additions & 0 deletions src/ooxml/java/org/apache/poi/xddf/usermodel/BlackWhiteMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */

package org.apache.poi.xddf.usermodel;

import java.util.HashMap;

import org.openxmlformats.schemas.drawingml.x2006.main.STBlackWhiteMode;

public enum BlackWhiteMode {
AUTO(STBlackWhiteMode.AUTO),
BLACK(STBlackWhiteMode.BLACK),
BLACK_GRAY(STBlackWhiteMode.BLACK_GRAY),
BLACK_WHITE(STBlackWhiteMode.BLACK_WHITE);

final STBlackWhiteMode.Enum underlying;

BlackWhiteMode(STBlackWhiteMode.Enum mode) {
this.underlying = mode;
}

private final static HashMap<STBlackWhiteMode.Enum, BlackWhiteMode> reverse = new HashMap<STBlackWhiteMode.Enum, BlackWhiteMode>();
static {
for (BlackWhiteMode value : values()) {
reverse.put(value.underlying, value);
}
}

static BlackWhiteMode valueOf(STBlackWhiteMode.Enum mode) {
return reverse.get(mode);
}
}
47 changes: 47 additions & 0 deletions src/ooxml/java/org/apache/poi/xddf/usermodel/CompoundLine.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */

package org.apache.poi.xddf.usermodel;

import java.util.HashMap;

import org.openxmlformats.schemas.drawingml.x2006.main.STCompoundLine;

public enum CompoundLine {
DOUBLE(STCompoundLine.DBL),
SINGLE(STCompoundLine.SNG),
THICK_THIN(STCompoundLine.THICK_THIN),
THIN_THICK(STCompoundLine.THIN_THICK),
TRIPLE(STCompoundLine.TRI);

final STCompoundLine.Enum underlying;

CompoundLine(STCompoundLine.Enum line) {
this.underlying = line;
}

private final static HashMap<STCompoundLine.Enum, CompoundLine> reverse = new HashMap<STCompoundLine.Enum, CompoundLine>();
static {
for (CompoundLine value : values()) {
reverse.put(value.underlying, value);
}
}

static CompoundLine valueOf(STCompoundLine.Enum LineEndWidth) {
return reverse.get(LineEndWidth);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */

package org.apache.poi.xddf.usermodel;

public interface HasShapeProperties {
XDDFShapeProperties getOrAddShapeProperties();
}
45 changes: 45 additions & 0 deletions src/ooxml/java/org/apache/poi/xddf/usermodel/LineCap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */

package org.apache.poi.xddf.usermodel;

import java.util.HashMap;

import org.openxmlformats.schemas.drawingml.x2006.main.STLineCap;

public enum LineCap {
FLAT(STLineCap.FLAT),
ROUND(STLineCap.RND),
SQUARE(STLineCap.SQ);

final STLineCap.Enum underlying;

LineCap(STLineCap.Enum line) {
this.underlying = line;
}

private final static HashMap<STLineCap.Enum, LineCap> reverse = new HashMap<STLineCap.Enum, LineCap>();
static {
for (LineCap value : values()) {
reverse.put(value.underlying, value);
}
}

static LineCap valueOf(STLineCap.Enum LineEndWidth) {
return reverse.get(LineEndWidth);
}
}
45 changes: 45 additions & 0 deletions src/ooxml/java/org/apache/poi/xddf/usermodel/LineEndLength.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */

package org.apache.poi.xddf.usermodel;

import java.util.HashMap;

import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndLength;

public enum LineEndLength {
LARGE(STLineEndLength.LG),
MEDIUM(STLineEndLength.MED),
SMALL(STLineEndLength.SM);

final STLineEndLength.Enum underlying;

LineEndLength(STLineEndLength.Enum lineEnd) {
this.underlying = lineEnd;
}

private final static HashMap<STLineEndLength.Enum, LineEndLength> reverse = new HashMap<STLineEndLength.Enum, LineEndLength>();
static {
for (LineEndLength value : values()) {
reverse.put(value.underlying, value);
}
}

static LineEndLength valueOf(STLineEndLength.Enum LineEndWidth) {
return reverse.get(LineEndWidth);
}
}
Loading