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);
}
}
}
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);
}
}
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;
}
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);
}
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();
}
}
Aggregations