use of org.apache.poi.ss.util.CellRangeAddress in project Robot-Scouter by SUPERCILEX.
the class SpreadsheetExporter method setupRow.
private void setupRow(Row row, TeamHelper teamHelper, Metric metric) {
Cell headerCell = row.getCell(0, MissingCellPolicy.CREATE_NULL_AS_BLANK);
mCache.putKeyMetric(headerCell, metric);
if (metric.getType() == HEADER) {
headerCell.setCellStyle(mCache.getHeaderMetricRowHeaderStyle());
int numOfScouts = mScouts.get(teamHelper).size();
if (numOfScouts > SINGLE_ITEM) {
int rowNum = row.getRowNum();
row.getSheet().addMergedRegion(new CellRangeAddress(rowNum, rowNum, 1, numOfScouts));
}
} else {
headerCell.setCellStyle(mCache.getRowHeaderStyle());
}
}
use of org.apache.poi.ss.util.CellRangeAddress 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.util.CellRangeAddress in project Robot-Scouter by SUPERCILEX.
the class SpreadsheetExporter method buildAverageColumn.
@AddTrace(name = "buildAverageColumn")
private void buildAverageColumn(Sheet sheet, TeamHelper teamHelper) {
int farthestColumn = 0;
for (Row row : sheet) {
int last = row.getLastCellNum();
if (last > farthestColumn)
farthestColumn = last;
}
Map<Chart, Pair<LineChartData, List<ChartAxis>>> chartData = new HashMap<>();
Map<Metric<Void>, Chart> chartPool = new HashMap<>();
Iterator<Row> rowIterator = sheet.rowIterator();
for (int i = 0; rowIterator.hasNext(); i++) {
Row row = rowIterator.next();
Cell cell = row.createCell(farthestColumn);
if (i == 0) {
cell.setCellValue(getString(R.string.average));
cell.setCellStyle(mCache.getColumnHeaderStyle());
continue;
}
Cell first = row.getCell(1, MissingCellPolicy.CREATE_NULL_AS_BLANK);
cell.setCellStyle(first.getCellStyle());
int type = getMetricForScouts(mScouts.get(teamHelper), mCache.getMetricKey(row)).getType();
String rangeAddress = getCellRangeAddress(first, row.getCell(cell.getColumnIndex() - 1, MissingCellPolicy.CREATE_NULL_AS_BLANK));
switch(type) {
case BOOLEAN:
cell.setCellFormula("COUNTIF(" + rangeAddress + ", TRUE) / COUNTA(" + rangeAddress + ")");
mCache.setCellFormat(cell, "0.00%");
break;
case NUMBER:
cell.setCellFormula("SUM(" + rangeAddress + ")" + " / " + "COUNT(" + rangeAddress + ")");
buildTeamChart(row, teamHelper, chartData, chartPool);
break;
case STOPWATCH:
String excludeZeros = "\"<>0\"";
cell.setCellFormula("IF(COUNTIF(" + rangeAddress + ", " + excludeZeros + ") = 0, 0, AVERAGEIF(" + rangeAddress + ", " + excludeZeros + "))");
buildTeamChart(row, teamHelper, chartData, chartPool);
break;
case LIST:
sheet.setArrayFormula("INDEX(" + rangeAddress + ", " + "MATCH(" + "MAX(" + "COUNTIF(" + rangeAddress + ", " + rangeAddress + ")" + "), " + "COUNTIF(" + rangeAddress + ", " + rangeAddress + ")" + ", 0))", new CellRangeAddress(cell.getRowIndex(), cell.getRowIndex(), cell.getColumnIndex(), cell.getColumnIndex()));
break;
case HEADER:
case TEXT:
// Nothing to average
break;
default:
throw new IllegalStateException();
}
}
for (Chart chart : chartData.keySet()) {
Pair<LineChartData, List<ChartAxis>> data = chartData.get(chart);
chart.plot(data.first, data.second.toArray(new ChartAxis[data.second.size()]));
if (chart instanceof XSSFChart) {
XSSFChart xChart = (XSSFChart) chart;
CTChart ctChart = xChart.getCTChart();
CTPlotArea plotArea = ctChart.getPlotArea();
setChartAxisTitle(plotArea.getValAxArray(0).addNewTitle(), "Values");
setChartAxisTitle(plotArea.getCatAxArray(0).addNewTitle(), "Scouts");
String name = getMetricForChart(xChart, chartPool).getName();
if (!TextUtils.isEmpty(name))
xChart.setTitle(name);
}
}
}
use of org.apache.poi.ss.util.CellRangeAddress in project poi by apache.
the class MergedCells method main.
public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
HSSFRow row = sheet.createRow(1);
HSSFCell cell = row.createCell(1);
cell.setCellValue("This is a test of merging");
sheet.addMergedRegion(new CellRangeAddress(1, 1, 1, 2));
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
wb.close();
}
use of org.apache.poi.ss.util.CellRangeAddress in project poi by apache.
the class CFRecordsAggregate method shiftRange.
private static CellRangeAddress shiftRange(FormulaShifter shifter, CellRangeAddress cra, int currentExternSheetIx) {
// FormulaShifter works well in terms of Ptgs - so convert CellRangeAddress to AreaPtg (and back) here
AreaPtg aptg = new AreaPtg(cra.getFirstRow(), cra.getLastRow(), cra.getFirstColumn(), cra.getLastColumn(), false, false, false, false);
Ptg[] ptgs = { aptg };
if (!shifter.adjustFormula(ptgs, currentExternSheetIx)) {
return cra;
}
Ptg ptg0 = ptgs[0];
if (ptg0 instanceof AreaPtg) {
AreaPtg bptg = (AreaPtg) ptg0;
return new CellRangeAddress(bptg.getFirstRow(), bptg.getLastRow(), bptg.getFirstColumn(), bptg.getLastColumn());
}
if (ptg0 instanceof AreaErrPtg) {
return null;
}
throw new IllegalStateException("Unexpected shifted ptg class (" + ptg0.getClass().getName() + ")");
}
Aggregations