use of org.apache.poi.xssf.usermodel.XSSFDrawing in project poi by apache.
the class XSSFExcelExtractor method getText.
/**
* Retrieves the text contents of the file
*/
public String getText() {
DataFormatter formatter;
if (locale == null) {
formatter = new DataFormatter();
} else {
formatter = new DataFormatter(locale);
}
StringBuffer text = new StringBuffer();
for (Sheet sh : workbook) {
XSSFSheet sheet = (XSSFSheet) sh;
if (includeSheetNames) {
text.append(sheet.getSheetName()).append("\n");
}
// Header(s), if present
if (includeHeadersFooters) {
text.append(extractHeaderFooter(sheet.getFirstHeader()));
text.append(extractHeaderFooter(sheet.getOddHeader()));
text.append(extractHeaderFooter(sheet.getEvenHeader()));
}
// Rows and cells
for (Object rawR : sheet) {
Row row = (Row) rawR;
for (Iterator<Cell> ri = row.cellIterator(); ri.hasNext(); ) {
Cell cell = ri.next();
// Is it a formula one?
if (cell.getCellTypeEnum() == CellType.FORMULA) {
if (formulasNotResults) {
String contents = cell.getCellFormula();
checkMaxTextSize(text, contents);
text.append(contents);
} else {
if (cell.getCachedFormulaResultTypeEnum() == CellType.STRING) {
handleStringCell(text, cell);
} else {
handleNonStringCell(text, cell, formatter);
}
}
} else if (cell.getCellTypeEnum() == CellType.STRING) {
handleStringCell(text, cell);
} else {
handleNonStringCell(text, cell, formatter);
}
// Output the comment, if requested and exists
Comment comment = cell.getCellComment();
if (includeCellComments && comment != null) {
// Replace any newlines with spaces, otherwise it
// breaks the output
String commentText = comment.getString().getString().replace('\n', ' ');
checkMaxTextSize(text, commentText);
text.append(" Comment by ").append(comment.getAuthor()).append(": ").append(commentText);
}
if (ri.hasNext()) {
text.append("\t");
}
}
text.append("\n");
}
// add textboxes
if (includeTextBoxes) {
XSSFDrawing drawing = sheet.getDrawingPatriarch();
if (drawing != null) {
for (XSSFShape shape : drawing.getShapes()) {
if (shape instanceof XSSFSimpleShape) {
String boxText = ((XSSFSimpleShape) shape).getText();
if (boxText.length() > 0) {
text.append(boxText);
text.append('\n');
}
}
}
}
}
// Finally footer(s), if present
if (includeHeadersFooters) {
text.append(extractHeaderFooter(sheet.getFirstFooter()));
text.append(extractHeaderFooter(sheet.getOddFooter()));
text.append(extractHeaderFooter(sheet.getEvenFooter()));
}
}
return text.toString();
}
use of org.apache.poi.xssf.usermodel.XSSFDrawing in project ocvn by devgateway.
the class TotalCancelledTendersExcelControllerTest method cancelledFundingExcelChart.
@Test
public void cancelledFundingExcelChart() throws Exception {
LangYearFilterPagingRequest filter = getLangYearFilterMockRequest();
totalCancelledTendersExcelController.cancelledFundingExcelChart(filter, mockHttpServletResponse);
final byte[] responseOutput = mockHttpServletResponse.getContentAsByteArray();
final Workbook workbook = new XSSFWorkbook(new ByteArrayInputStream(responseOutput));
Assert.assertNotNull(workbook);
final Sheet sheet = workbook.getSheet(ChartType.area.toString());
Assert.assertNotNull("check chart type, sheet name should be the same as the type", sheet);
final XSSFDrawing drawing = (XSSFDrawing) sheet.getDrawingPatriarch();
final List<XSSFChart> charts = drawing.getCharts();
Assert.assertEquals("number of charts", 1, charts.size());
final XSSFChart chart = charts.get(0);
Assert.assertEquals("chart title", translationService.getValue(filter.getLanguage(), "charts:cancelledAmounts:title"), chart.getTitle().getString());
final List<? extends XSSFChartAxis> axis = chart.getAxis();
Assert.assertEquals("number of axis", 2, axis.size());
final CTChart ctChart = chart.getCTChart();
Assert.assertEquals("Check if we have 1 area chart", 1, ctChart.getPlotArea().getAreaChartArray().length);
}
use of org.apache.poi.xssf.usermodel.XSSFDrawing in project ocvn by devgateway.
the class AverageNumberOfTenderersExcelControllerTest method averageNumberBidsExcelChart.
@Test
public void averageNumberBidsExcelChart() throws Exception {
LangYearFilterPagingRequest filter = getLangYearFilterMockRequest();
averageNumberOfTenderersExcelController.averageNumberBidsExcelChart(filter, mockHttpServletResponse);
final byte[] responseOutput = mockHttpServletResponse.getContentAsByteArray();
final Workbook workbook = new XSSFWorkbook(new ByteArrayInputStream(responseOutput));
Assert.assertNotNull(workbook);
final Sheet sheet = workbook.getSheet(ChartType.barcol.toString());
Assert.assertNotNull("check chart type, sheet name should be the same as the type", sheet);
final XSSFDrawing drawing = (XSSFDrawing) sheet.getDrawingPatriarch();
final List<XSSFChart> charts = drawing.getCharts();
Assert.assertEquals("number of charts", 1, charts.size());
final XSSFChart chart = charts.get(0);
Assert.assertEquals("chart title", translationService.getValue(filter.getLanguage(), "charts:avgNrBids:title"), chart.getTitle().getString());
final List<? extends XSSFChartAxis> axis = chart.getAxis();
Assert.assertEquals("number of axis", 2, axis.size());
final CTChart ctChart = chart.getCTChart();
Assert.assertEquals("Check if we have 1 bar chart", 1, ctChart.getPlotArea().getBarChartArray().length);
}
use of org.apache.poi.xssf.usermodel.XSSFDrawing in project ocvn by devgateway.
the class AverageTenderAndAwardsExcelControllerTest method bidTimelineExcelChart.
@Test
public void bidTimelineExcelChart() throws Exception {
LangYearFilterPagingRequest filter = getLangYearFilterMockRequest();
averageTenderAndAwardsExcelController.bidTimelineExcelChart(filter, mockHttpServletResponse);
final byte[] responseOutput = mockHttpServletResponse.getContentAsByteArray();
final Workbook workbook = new XSSFWorkbook(new ByteArrayInputStream(responseOutput));
Assert.assertNotNull(workbook);
final Sheet sheet = workbook.getSheet(ChartType.stackedbar.toString());
Assert.assertNotNull("check chart type, sheet name should be the same as the type", sheet);
final XSSFDrawing drawing = (XSSFDrawing) sheet.getDrawingPatriarch();
final List<XSSFChart> charts = drawing.getCharts();
Assert.assertEquals("number of charts", 1, charts.size());
final XSSFChart chart = charts.get(0);
Assert.assertEquals("chart title", translationService.getValue(filter.getLanguage(), "charts:bidPeriod:title"), chart.getTitle().getString());
final List<? extends XSSFChartAxis> axis = chart.getAxis();
Assert.assertEquals("number of axis", 2, axis.size());
final CTChart ctChart = chart.getCTChart();
Assert.assertEquals("Check if we have 1 bar chart", 1, ctChart.getPlotArea().getBarChartArray().length);
}
use of org.apache.poi.xssf.usermodel.XSSFDrawing in project ocvn by devgateway.
the class CostEffectivenessExcelControllerTest method costEffectivenessExcelChart.
@Test
public void costEffectivenessExcelChart() throws Exception {
LangGroupingFilterPagingRequest filter = getLangGroupingFilterMockRequest();
costEffectivenessExcelController.costEffectivenessExcelChart(filter, mockHttpServletResponse);
final byte[] responseOutput = mockHttpServletResponse.getContentAsByteArray();
final Workbook workbook = new XSSFWorkbook(new ByteArrayInputStream(responseOutput));
Assert.assertNotNull(workbook);
final Sheet sheet = workbook.getSheet(ChartType.stackedcol.toString());
Assert.assertNotNull("check chart type, sheet name should be the same as the type", sheet);
final XSSFDrawing drawing = (XSSFDrawing) sheet.getDrawingPatriarch();
final List<XSSFChart> charts = drawing.getCharts();
Assert.assertEquals("number of charts", 1, charts.size());
final XSSFChart chart = charts.get(0);
Assert.assertEquals("chart title", translationService.getValue(filter.getLanguage(), "charts:costEffectiveness:title"), chart.getTitle().getString());
final List<? extends XSSFChartAxis> axis = chart.getAxis();
Assert.assertEquals("number of axis", 2, axis.size());
final CTChart ctChart = chart.getCTChart();
Assert.assertEquals("Check if we have 1 bar chart", 1, ctChart.getPlotArea().getBarChartArray().length);
}
Aggregations