Search in sources :

Example 6 with Row

use of org.apache.poi.ss.usermodel.Row in project Robot-Scouter by SUPERCILEX.

the class SpreadsheetExporter method buildAverageCharts.

@AddTrace(name = "buildAverageCharts")
private void buildAverageCharts(Sheet sheet) {
    if (isUnsupportedDevice())
        return;
    Drawing drawing = sheet.createDrawingPatriarch();
    List<Cell> headerCells = getAdjustedList(sheet.getRow(0));
    for (Cell cell : headerCells) {
        int columnIndex = cell.getColumnIndex();
        String headerName = cell.getStringCellValue();
        ClientAnchor anchor = createChartAnchor(drawing, sheet.getLastRowNum() + 3, columnIndex, columnIndex + 1);
        anchor.setRow2(anchor.getRow2() + 30);
        Chart chart = drawing.createChart(anchor);
        chart.getOrCreateLegend().setPosition(LegendPosition.BOTTOM);
        ChartDataSource<String> categorySource = DataSources.fromArray(new String[] { headerName });
        ScatterChartData data = chart.getChartDataFactory().createScatterChartData();
        List<Row> dataRows = getAdjustedList(sheet);
        for (Row row : dataRows) {
            data.addSerie(categorySource, DataSources.fromNumericCellRange(sheet, new CellRangeAddress(row.getRowNum(), row.getRowNum(), columnIndex, columnIndex))).setTitle(row.getCell(0).getStringCellValue());
        }
        ChartAxis bottomAxis = chart.getChartAxisFactory().createCategoryAxis(AxisPosition.BOTTOM);
        ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
        leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);
        chart.plot(data, bottomAxis, leftAxis);
        if (chart instanceof XSSFChart) {
            CTPlotArea plotArea = ((XSSFChart) chart).getCTChart().getPlotArea();
            setChartAxisTitle(plotArea.getValAxArray(0).addNewTitle(), "Values");
            setChartAxisTitle(plotArea.getCatAxArray(0).addNewTitle(), headerName);
        }
    }
}
Also used : Drawing(org.apache.poi.ss.usermodel.Drawing) CTPlotArea(org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea) RichTextString(org.apache.poi.ss.usermodel.RichTextString) ScatterChartData(org.apache.poi.ss.usermodel.charts.ScatterChartData) PreferencesUtilsKt.setShouldShowExportHint(com.supercilex.robotscouter.util.PreferencesUtilsKt.setShouldShowExportHint) PreferencesUtilsKt.shouldShowExportHint(com.supercilex.robotscouter.util.PreferencesUtilsKt.shouldShowExportHint) XSSFChart(org.apache.poi.xssf.usermodel.XSSFChart) ClientAnchor(org.apache.poi.ss.usermodel.ClientAnchor) ChartAxis(org.apache.poi.ss.usermodel.charts.ChartAxis) ValueAxis(org.apache.poi.ss.usermodel.charts.ValueAxis) Row(org.apache.poi.ss.usermodel.Row) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) SpreadsheetUtils.getCellRangeAddress(com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getCellRangeAddress) Cell(org.apache.poi.ss.usermodel.Cell) SpreadsheetUtils.getStringForCell(com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getStringForCell) XSSFChart(org.apache.poi.xssf.usermodel.XSSFChart) Chart(org.apache.poi.ss.usermodel.Chart) CTChart(org.openxmlformats.schemas.drawingml.x2006.chart.CTChart) SpreadsheetUtils.getMetricForChart(com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getMetricForChart) AddTrace(com.google.firebase.perf.metrics.AddTrace)

Example 7 with Row

use of org.apache.poi.ss.usermodel.Row in project Robot-Scouter by SUPERCILEX.

the class SpreadsheetExporter method buildTeamSheet.

@AddTrace(name = "buildTeamSheet")
private void buildTeamSheet(TeamHelper teamHelper, Sheet teamSheet) {
    List<Scout> scouts = mScouts.get(teamHelper);
    if (scouts.isEmpty()) {
        Workbook workbook = teamSheet.getWorkbook();
        workbook.removeSheetAt(workbook.getSheetIndex(teamSheet));
        return;
    }
    Row header = teamSheet.createRow(0);
    // Create empty top left corner cell
    header.createCell(0);
    List<Metric<?>> orderedMetrics = scouts.get(scouts.size() - 1).getMetrics();
    for (int i = 0; i < orderedMetrics.size(); i++) {
        Metric metric = orderedMetrics.get(i);
        Row row = teamSheet.createRow(i + 1);
        setupRow(row, teamHelper, metric);
    }
    for (int i = 0, column = 1; i < scouts.size(); i++, column++) {
        Scout scout = scouts.get(i);
        List<Metric<?>> metrics = scout.getMetrics();
        Cell cell = header.getCell(column, MissingCellPolicy.CREATE_NULL_AS_BLANK);
        String name = scout.getName();
        cell.setCellValue(TextUtils.isEmpty(name) ? "Scout " + column : name);
        cell.setCellStyle(mCache.getColumnHeaderStyle());
        columnIterator: for (int j = 0, rowNum = 1; j < metrics.size(); j++, rowNum++) {
            Metric metric = metrics.get(j);
            Row row = teamSheet.getRow(rowNum);
            if (row == null) {
                setupRowAndSetValue(teamSheet.createRow(rowNum), teamHelper, metric, column);
            } else {
                List<Row> rows = getAdjustedList(teamSheet);
                for (Row row1 : rows) {
                    Cell cell1 = row1.getCell(0);
                    if (TextUtils.equals(mCache.getMetricKey(row1), metric.getRef().getKey())) {
                        setRowValue(column, metric, row1);
                        if (TextUtils.isEmpty(cell1.getStringCellValue())) {
                            cell1.setCellValue(metric.getName());
                        }
                        continue columnIterator;
                    }
                }
                setupRowAndSetValue(teamSheet.createRow(teamSheet.getLastRowNum() + 1), teamHelper, metric, column);
            }
        }
    }
    if (scouts.size() > SINGLE_ITEM) {
        buildAverageColumn(teamSheet, teamHelper);
    }
}
Also used : Metric(com.supercilex.robotscouter.data.model.Metric) ArrayList(java.util.ArrayList) SpreadsheetUtils.getAdjustedList(com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getAdjustedList) List(java.util.List) Row(org.apache.poi.ss.usermodel.Row) RichTextString(org.apache.poi.ss.usermodel.RichTextString) Cell(org.apache.poi.ss.usermodel.Cell) SpreadsheetUtils.getStringForCell(com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getStringForCell) Scout(com.supercilex.robotscouter.data.model.Scout) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) PreferencesUtilsKt.setShouldShowExportHint(com.supercilex.robotscouter.util.PreferencesUtilsKt.setShouldShowExportHint) PreferencesUtilsKt.shouldShowExportHint(com.supercilex.robotscouter.util.PreferencesUtilsKt.shouldShowExportHint) AddTrace(com.google.firebase.perf.metrics.AddTrace)

Example 8 with Row

use of org.apache.poi.ss.usermodel.Row in project textdb by TextDB.

the class ExcelSink method open.

@Override
public void open() throws TextDBException {
    if (cursor != CLOSED) {
        return;
    }
    inputOperator.open();
    inputSchema = inputOperator.getOutputSchema();
    outputSchema = new Schema(inputSchema.getAttributes().stream().filter(attr -> !attr.getAttributeName().equalsIgnoreCase(SchemaConstants._ID)).filter(attr -> !attr.getAttributeName().equalsIgnoreCase(SchemaConstants.PAYLOAD)).filter(attr -> !attr.getAttributeType().equals(AttributeType.LIST)).toArray(Attribute[]::new));
    wb = new XSSFWorkbook();
    DateFormat df = new SimpleDateFormat("yyyyMMdd-HHmmss");
    fileName = df.format(new Date()) + ".xlsx";
    try {
        if (Files.notExists(Paths.get(excelIndexDirectory))) {
            Files.createDirectories(Paths.get(excelIndexDirectory));
        }
        fileOut = new FileOutputStream(Paths.get(excelIndexDirectory, fileName).toString());
    } catch (IOException e) {
        throw new DataFlowException(e);
    }
    sheet = wb.createSheet("new sheet");
    Row row = sheet.createRow(0);
    List<String> attributeNames = outputSchema.getAttributeNames();
    for (int i = 0; i < attributeNames.size(); i++) {
        String attributeName = attributeNames.get(i);
        row.createCell(i).setCellValue(attributeName);
    }
    cursor = OPENED;
}
Also used : SchemaConstants(edu.uci.ics.textdb.api.constants.SchemaConstants) DoubleField(edu.uci.ics.textdb.api.field.DoubleField) DateField(edu.uci.ics.textdb.api.field.DateField) Date(java.util.Date) DataFlowException(edu.uci.ics.textdb.api.exception.DataFlowException) SimpleDateFormat(java.text.SimpleDateFormat) ArrayList(java.util.ArrayList) AttributeType(edu.uci.ics.textdb.api.schema.AttributeType) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) IntegerField(edu.uci.ics.textdb.api.field.IntegerField) ISink(edu.uci.ics.textdb.api.dataflow.ISink) TextDBException(edu.uci.ics.textdb.api.exception.TextDBException) Cell(org.apache.poi.ss.usermodel.Cell) DateFormat(java.text.DateFormat) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) IOperator(edu.uci.ics.textdb.api.dataflow.IOperator) Sheet(org.apache.poi.ss.usermodel.Sheet) Attribute(edu.uci.ics.textdb.api.schema.Attribute) Files(java.nio.file.Files) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Utils(edu.uci.ics.textdb.api.utils.Utils) Schema(edu.uci.ics.textdb.api.schema.Schema) List(java.util.List) Workbook(org.apache.poi.ss.usermodel.Workbook) Paths(java.nio.file.Paths) IField(edu.uci.ics.textdb.api.field.IField) Row(org.apache.poi.ss.usermodel.Row) Schema(edu.uci.ics.textdb.api.schema.Schema) IOException(java.io.IOException) Date(java.util.Date) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) FileOutputStream(java.io.FileOutputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) DataFlowException(edu.uci.ics.textdb.api.exception.DataFlowException) Row(org.apache.poi.ss.usermodel.Row) SimpleDateFormat(java.text.SimpleDateFormat)

Example 9 with Row

use of org.apache.poi.ss.usermodel.Row in project ats-framework by Axway.

the class ExcelParser method determineTestDataFrame.

/**
     * Iterates through the sheet and determines the cells that are between START_TEST_CASE and END_TEST_CASE comments.
     * Also determines if the data table is to be returned as a Cartesian product of the rows.
     * @param sheet
     * @throws DataProviderException
     */
private void determineTestDataFrame(Sheet sheet) throws DataProviderException {
    int rows = sheet.getLastRowNum() + 1;
    int columns = sheet.getRow(sheet.getLastRowNum()).getLastCellNum();
    // iterate throughout the spreadsheet's cells
    for (int x = 0; x < columns; x++) {
        for (int y = 0; y < rows; y++) {
            Row rowValue = sheet.getRow(y);
            if (rowValue != null) {
                if (rowValue.getLastCellNum() > columns) {
                    columns = rowValue.getLastCellNum();
                }
                Cell current = rowValue.getCell(x, Row.CREATE_NULL_AS_BLANK);
                if (hasComments(current)) {
                    if (isStartingCell(current)) {
                        this.startingCell = current;
                    }
                    if (isEndingCell(current)) {
                        this.endingCell = current;
                    }
                    if (isMultiplyCell(current)) {
                        this.isMultipliable = true;
                    }
                }
            }
        }
    }
    if (this.startingCell == null) {
        throw new DataProviderException(ERROR_LOCATING_STARTING_CELL);
    } else if (this.endingCell == null) {
        throw new DataProviderException(ERROR_LOCATING_ENDING_CELL);
    }
    if (this.startingCell.getRowIndex() <= this.endingCell.getRowIndex()) {
        if (this.startingCell.getColumnIndex() <= this.endingCell.getColumnIndex()) {
            return;
        }
    }
    throw new DataProviderException(WRONG_ORDER);
}
Also used : Row(org.apache.poi.ss.usermodel.Row) Cell(org.apache.poi.ss.usermodel.Cell) DataProviderException(com.axway.ats.harness.testng.exceptions.DataProviderException)

Example 10 with Row

use of org.apache.poi.ss.usermodel.Row in project ats-framework by Axway.

the class ExcelParser method makeCartesianProductTable.

private void makeCartesianProductTable(int startCol, int startRow, int endCol, int endRow, Sheet sheet, Method method) throws DataProviderException {
    // List of columns
    ArrayList<ArrayList<Object>> productTable = new ArrayList<ArrayList<Object>>();
    // Read the data sheet and fill the list of columns
    for (int x = 0, col = startCol; col <= endCol; ++col, ++x) {
        productTable.add(new ArrayList<Object>());
        Class<?> parameterType = getParameterTypeAt(method, x);
        for (int row = startRow; row <= endRow; ++row) {
            Row rowValue = sheet.getRow(row);
            if (rowValue != null) {
                Cell currentCell = rowValue.getCell(col, Row.CREATE_NULL_AS_BLANK);
                Object currentObject = parseCellContents(currentCell, parameterType);
                if (!(currentObject instanceof SkipObject)) {
                    productTable.get(x).add(currentObject);
                }
            }
        }
    }
    // Multiplication:
    int fields = productTable.size();
    int[] counts = new int[fields];
    int totalRows = 1;
    for (int i = 0; i < fields; i++) {
        counts[i] = productTable.get(i).size();
        totalRows *= counts[i];
    }
    int columns = endCol - startCol + 1;
    this.workingObjectArray = new Object[totalRows][columns];
    this.log.debug(CREATING_MULTIPLY_DATA_BLOCK + columns + "/" + totalRows);
    // Fill the new data table
    for (int t = 0; t < totalRows; t++) {
        // iterate through all the rows that will be in the new table after multiplication
        ArrayList<Object> buff = new ArrayList<Object>();
        for (int x = 0; x < fields; x++) {
            // iterate through the columns of the extracted table
            int pos = t;
            // calculating the column index of the element to be added in the current row
            for (int y = 0; y < x; y++) {
                pos /= counts[y];
            }
            pos %= counts[x];
            // get the current column
            Object[] members = productTable.get(x).toArray();
            // get the appropriate element from the column
            Object member = members[pos];
            buff.add(member);
        }
        // add the row to the resulting table
        this.workingObjectArray[t] = buff.toArray();
    }
}
Also used : ArrayList(java.util.ArrayList) Row(org.apache.poi.ss.usermodel.Row) Cell(org.apache.poi.ss.usermodel.Cell)

Aggregations

Row (org.apache.poi.ss.usermodel.Row)289 Cell (org.apache.poi.ss.usermodel.Cell)218 Sheet (org.apache.poi.ss.usermodel.Sheet)174 Workbook (org.apache.poi.ss.usermodel.Workbook)122 Test (org.junit.Test)112 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)55 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)39 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)33 CellStyle (org.apache.poi.ss.usermodel.CellStyle)27 CellReference (org.apache.poi.ss.util.CellReference)22 FileOutputStream (java.io.FileOutputStream)19 ArrayList (java.util.ArrayList)19 XSSFColor (org.apache.poi.xssf.usermodel.XSSFColor)17 XSSFFont (org.apache.poi.xssf.usermodel.XSSFFont)17 HashMap (java.util.HashMap)16 RichTextString (org.apache.poi.ss.usermodel.RichTextString)16 XSSFCellStyle (org.apache.poi.xssf.usermodel.XSSFCellStyle)16 IOException (java.io.IOException)14 List (java.util.List)13 FormulaEvaluator (org.apache.poi.ss.usermodel.FormulaEvaluator)13