Search in sources :

Example 1 with XSSFDrawing

use of org.apache.poi.xssf.usermodel.XSSFDrawing in project poi by apache.

the class TestXSSFChartTitle method getChartFromWorkbook.

/**
     * Gets the first chart from the named sheet in the workbook.
     */
private XSSFChart getChartFromWorkbook(Workbook wb, String sheetName) {
    Sheet sheet = wb.getSheet(sheetName);
    if (sheet instanceof XSSFSheet) {
        XSSFSheet xsheet = (XSSFSheet) sheet;
        XSSFDrawing drawing = xsheet.getDrawingPatriarch();
        if (drawing != null) {
            List<XSSFChart> charts = drawing.getCharts();
            if (charts != null && charts.size() > 0) {
                return charts.get(0);
            }
        }
    }
    return null;
}
Also used : XSSFChart(org.apache.poi.xssf.usermodel.XSSFChart) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) Sheet(org.apache.poi.ss.usermodel.Sheet) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) XSSFDrawing(org.apache.poi.xssf.usermodel.XSSFDrawing)

Example 2 with XSSFDrawing

use of org.apache.poi.xssf.usermodel.XSSFDrawing in project bamboobsc by billchen198318.

the class SimpleUtils method setCellPicture.

public static void setCellPicture(XSSFWorkbook wb, XSSFSheet sh, byte[] iconBytes, int row, int col) throws Exception {
    int myPictureId = wb.addPicture(iconBytes, XSSFWorkbook.PICTURE_TYPE_PNG);
    XSSFDrawing drawing = sh.createDrawingPatriarch();
    XSSFClientAnchor myAnchor = new XSSFClientAnchor();
    myAnchor.setCol1(col);
    myAnchor.setRow1(row);
    XSSFPicture myPicture = drawing.createPicture(myAnchor, myPictureId);
    myPicture.resize();
}
Also used : XSSFClientAnchor(org.apache.poi.xssf.usermodel.XSSFClientAnchor) XSSFPicture(org.apache.poi.xssf.usermodel.XSSFPicture) XSSFDrawing(org.apache.poi.xssf.usermodel.XSSFDrawing)

Example 3 with XSSFDrawing

use of org.apache.poi.xssf.usermodel.XSSFDrawing in project Gargoyle by callakrsos.

the class ExcelUtil method addComment.

/**
	 * 특정셀에 코멘트를 추가한다.
	 *
	 * @param sheet
	 * @param cell
	 * @param commentText
	 * @return
	 */
public static void addComment(Sheet sheet, Cell cell, String commentText) {
    XSSFDrawing patr = (XSSFDrawing) sheet.createDrawingPatriarch();
    Comment comment = patr.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 4, 2, (short) 6, 5));
    comment.setString(new XSSFRichTextString(commentText));
    cell.setCellComment(comment);
}
Also used : Comment(org.apache.poi.ss.usermodel.Comment) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) XSSFClientAnchor(org.apache.poi.xssf.usermodel.XSSFClientAnchor) XSSFDrawing(org.apache.poi.xssf.usermodel.XSSFDrawing)

Example 4 with XSSFDrawing

use of org.apache.poi.xssf.usermodel.XSSFDrawing in project ocvn by devgateway.

the class TotalCancelledTendersExcelControllerTest method cancelledTendersByYearByRationaleExcelChart.

@Test
public void cancelledTendersByYearByRationaleExcelChart() throws Exception {
    LangYearFilterPagingRequest filter = getLangYearFilterMockRequest();
    totalCancelledTendersExcelController.cancelledTendersByYearByRationaleExcelChart(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:cancelledFunding: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);
}
Also used : XSSFChart(org.apache.poi.xssf.usermodel.XSSFChart) LangYearFilterPagingRequest(org.devgateway.ocds.web.rest.controller.request.LangYearFilterPagingRequest) CTChart(org.openxmlformats.schemas.drawingml.x2006.chart.CTChart) ByteArrayInputStream(java.io.ByteArrayInputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Sheet(org.apache.poi.ss.usermodel.Sheet) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) XSSFDrawing(org.apache.poi.xssf.usermodel.XSSFDrawing) Test(org.junit.Test)

Example 5 with XSSFDrawing

use of org.apache.poi.xssf.usermodel.XSSFDrawing in project ocvn by devgateway.

the class TenderPercentagesExcelControllerTest method cancelledFundingPercentageExcelChart.

@Test
public void cancelledFundingPercentageExcelChart() throws Exception {
    LangYearFilterPagingRequest filter = getLangYearFilterMockRequest();
    tenderPercentagesExcelController.cancelledFundingPercentageExcelChart(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:cancelledPercents: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);
}
Also used : XSSFChart(org.apache.poi.xssf.usermodel.XSSFChart) LangYearFilterPagingRequest(org.devgateway.ocds.web.rest.controller.request.LangYearFilterPagingRequest) CTChart(org.openxmlformats.schemas.drawingml.x2006.chart.CTChart) ByteArrayInputStream(java.io.ByteArrayInputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Sheet(org.apache.poi.ss.usermodel.Sheet) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) XSSFDrawing(org.apache.poi.xssf.usermodel.XSSFDrawing) Test(org.junit.Test)

Aggregations

XSSFDrawing (org.apache.poi.xssf.usermodel.XSSFDrawing)19 Sheet (org.apache.poi.ss.usermodel.Sheet)17 XSSFChart (org.apache.poi.xssf.usermodel.XSSFChart)16 Workbook (org.apache.poi.ss.usermodel.Workbook)15 Test (org.junit.Test)15 CTChart (org.openxmlformats.schemas.drawingml.x2006.chart.CTChart)15 ByteArrayInputStream (java.io.ByteArrayInputStream)14 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)14 LangYearFilterPagingRequest (org.devgateway.ocds.web.rest.controller.request.LangYearFilterPagingRequest)13 Comment (org.apache.poi.ss.usermodel.Comment)2 XSSFClientAnchor (org.apache.poi.xssf.usermodel.XSSFClientAnchor)2 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)2 Cell (org.apache.poi.ss.usermodel.Cell)1 DataFormatter (org.apache.poi.ss.usermodel.DataFormatter)1 Row (org.apache.poi.ss.usermodel.Row)1 XSSFCell (org.apache.poi.xssf.usermodel.XSSFCell)1 XSSFPicture (org.apache.poi.xssf.usermodel.XSSFPicture)1 XSSFRichTextString (org.apache.poi.xssf.usermodel.XSSFRichTextString)1 XSSFShape (org.apache.poi.xssf.usermodel.XSSFShape)1 XSSFSimpleShape (org.apache.poi.xssf.usermodel.XSSFSimpleShape)1