/** * For the Convenience of Java Programmers maintaining pointers. * @see #setPrintArea(int, String) * @param sheetIndex Zero-based sheet index (0 = First Sheet) * @param startColumn Column to begin printarea * @param endColumn Column to end the printarea * @param startRow Row to begin the printarea * @param endRow Row to end the printarea */ public void setPrintArea(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow) { //using absolute references because they don't get copied and pasted anyway CellReference cell = new CellReference(startRow, startColumn, true, true); String reference = cell.formatAsString(); cell = new CellReference(endRow, endColumn, true, true); reference = reference+":"+cell.formatAsString(); setPrintArea(sheetIndex, reference); }
public static String[] validateColumnNames(String fieldNames[]) { final Map<String, Integer> uniqueFieldNames = Maps.newHashMap(); if (fieldNames != null) { for (int i = 0; i < fieldNames.length; ++i) { if (fieldNames[i].isEmpty()) { fieldNames[i] = CellReference.convertNumToColString(i); } // If we have seen this column name before, add a suffix final Integer count = uniqueFieldNames.get(fieldNames[i]); if (count != null) { uniqueFieldNames.put(fieldNames[i], count + 1); fieldNames[i] = fieldNames[i] + count; } else { uniqueFieldNames.put(fieldNames[i], 0); } } return fieldNames; } return null; }
private static CellReference cr(int rowIx, int colIxAndFlags) { int colIx = colIxAndFlags & 0x00FF; boolean isRowAbs = (colIxAndFlags & 0x8000) == 0; boolean isColAbs = (colIxAndFlags & 0x4000) == 0; return new CellReference(rowIx, colIx, isRowAbs, isColAbs); } }
public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append("[TABLE]\n"); buffer.append(" .range = ").append(getRange().toString()).append("\n"); buffer.append(" .flags = ") .append(HexDump.byteToHex(field_5_flags)).append("\n"); buffer.append(" .alwaysClc= ").append(isAlwaysCalc()).append("\n"); buffer.append(" .reserved = ").append(HexDump.intToHex(field_6_res)).append("\n"); CellReference crRowInput = cr(field_7_rowInputRow, field_8_colInputRow); CellReference crColInput = cr(field_9_rowInputCol, field_10_colInputCol); buffer.append(" .rowInput = ").append(crRowInput.formatAsString()).append("\n"); buffer.append(" .colInput = ").append(crColInput.formatAsString()).append("\n"); buffer.append("[/TABLE]\n"); return buffer.toString(); }
public void reportColumnWidth(String column, float width) { if (maxColumnWidths.containsKey(column)) { float current = maxColumnWidths.get(column); if (current < width) { maxColumnWidths.put(column, width); } } else { float colWidth = PDFHelper.excelToPixel(getSheet().getColumnWidth(CellReference.convertColStringToIndex(column))); maxColumnWidths.put(column, Math.max(width, colWidth)); } }
private static CellReference cr(int rowIx, int colIxAndFlags) { int colIx = colIxAndFlags & 0x00FF; boolean isRowAbs = (colIxAndFlags & 0x8000) == 0; boolean isColAbs = (colIxAndFlags & 0x4000) == 0; return new CellReference(rowIx, colIx, isRowAbs, isColAbs); } }
public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append("[TABLE]\n"); buffer.append(" .range = ").append(getRange().toString()).append("\n"); buffer.append(" .flags = ") .append(HexDump.byteToHex(field_5_flags)).append("\n"); buffer.append(" .alwaysClc= ").append(isAlwaysCalc()).append("\n"); buffer.append(" .reserved = ").append(HexDump.intToHex(field_6_res)).append("\n"); CellReference crRowInput = cr(field_7_rowInputRow, field_8_colInputRow); CellReference crColInput = cr(field_9_rowInputCol, field_10_colInputCol); buffer.append(" .rowInput = ").append(crRowInput.formatAsString()).append("\n"); buffer.append(" .colInput = ").append(crColInput.formatAsString()).append("\n"); buffer.append("[/TABLE]\n"); return buffer.toString(); }
/** * For the Convenience of Java Programmers maintaining pointers. * @see #setPrintArea(int, String) * @param sheetIndex Zero-based sheet index (0 = First Sheet) * @param startColumn Column to begin printarea * @param endColumn Column to end the printarea * @param startRow Row to begin the printarea * @param endRow Row to end the printarea */ public void setPrintArea(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow) { //using absolute references because they don't get copied and pasted anyway CellReference cell = new CellReference(startRow, startColumn, true, true); String reference = cell.formatAsString(); cell = new CellReference(endRow, endColumn, true, true); reference = reference+":"+cell.formatAsString(); setPrintArea(sheetIndex, reference); }
/** * Retrieves the column name associated with a given column index.<br> * If no column name is associated, generates a new column name using * {@link CellReference#convertNumToColString(int)} and caches that name * @param colIndex 0-based column index * @return column name */ public String getColumnName(Integer colIndex) { if (headersMap.containsKey(colIndex)) { return headersMap.get(colIndex); } else { final String columnName = CellReference.convertNumToColString(colIndex); return setColumnName(colIndex, columnName); } }
/** * check if any shapes contain wrong data * At now(13.08.2010) check if patriarch contains 2 or more comments with same coordinates */ protected void preSerialize(){ Map<Integer, NoteRecord> tailRecords = _boundAggregate.getTailRecords(); /** * contains coordinates of comments we iterate over */ Set<String> coordinates = new HashSet<String>(tailRecords.size()); for(NoteRecord rec : tailRecords.values()){ String noteRef = new CellReference(rec.getRow(), rec.getColumn()).formatAsString(); // A1-style notation if(coordinates.contains(noteRef )){ throw new IllegalStateException("found multiple cell comments for cell " + noteRef ); } else { coordinates.add(noteRef); } } }
@Override public String toString() { String letter = CellReference.convertNumToColString(cell.getColumnIndex()); String text = getText(); return String.format("column %s: '%s'", letter, text); }
private void fulfillExpectation(int currentRowCtr, int currentColCtr, Object cellValue, Class expectedClass) throws ScorecardParseException { List<DataExpectation> dataExpectations = resolveExpectations(currentRowCtr, currentColCtr); CellReference cellRef = new CellReference(currentRowCtr, currentColCtr); Method method = null; for (DataExpectation dataExpectation : dataExpectations) { if ( cellValue == null || StringUtils.isEmpty(cellValue.toString())){ if ( dataExpectation.errorMessage != null && !StringUtils.isEmpty(dataExpectation.errorMessage)) { parseErrors.add(new ScorecardError(cellRef.formatAsString(), dataExpectation.errorMessage)); return; if ( method == null ) { if (cellValue != null && !StringUtils.isEmpty(cellValue.toString())) { parseErrors.add(new ScorecardError(cellRef.formatAsString(), "Unexpected Value! Wrong Datatype?")); ((Extension) dataExpectation.object).setValue(cellRef.formatAsString());
public void setColumnWidths(XSSFWorkbook wb) { for (int i = 0; i < wb.getNumberOfSheets(); i++) { XSSFSheet sheet = wb.getSheetAt(i); Map<String, Float> maxColumnWidths = new HashMap<String, Float>(); for (int col = 0; col < 256; col++) { maxColumnWidths.put(CellReference.convertNumToColString(col), PDFHelper.excelToPixel(sheet.getColumnWidth(col))); } workbookColumnWidths.put(sheet, maxColumnWidths); } }
private float columnWidth(PdfContext context, int i) { String col = CellReference.convertNumToColString(i); return context.getMargins() + (context.isExpanded(col) ? context.getColumnWidth(col) : PDFHelper.excelToPixel(getSheet().getColumnWidth(i))); }
/** * Generate fields names per column in text file. * Read first line and count columns and return fields names like excel sheet. * A, B, C and so on. * * @return field name strings, null if no records found in text file. */ private String[] generateColumnNames() throws SchemaChangeException, IOException, ExecutionSetupException { assert (settings.isAutoGenerateColumnNames()); final boolean shouldSkipFirstLine = settings.isSkipFirstLine(); settings.setSkipFirstLine(false); final String[] columns = readFirstLineForColumnNames(); settings.setSkipFirstLine(shouldSkipFirstLine); if (columns != null && columns.length > 0) { String[] fieldNames = new String[columns.length]; for (int i = 0; i < columns.length; ++i) { fieldNames[i] = CellReference.convertNumToColString(i); } return fieldNames; } else { return null; } }
private void writeStyle(XLXContext context) throws IOException { long style = Sset ? s : -1 ; String fill = getFill(context); String id = CellReference.convertNumToColString(getCell().getColumnIndex()) + Long.toString(context.getCurrentRow() + 1 ) ; if(style > 0){ context.write("<td "+ ( getAxis() != null ? "axis=\"" + getAxis() + "\"" : "") + " id=" + id + " bgcolor=" + fill + " class='c" + style + "'>"); }else { context.write("<td " + ( getAxis() != null ? "axis=\"" + getAxis() + "\"" : "") + " id=" + id + " bgcolor=" + fill + ">"); } }
public PdfCellNode(XSSFSheet sheet, XSSFCell cell, XLSXExpression expr) { super(sheet, cell, expr); excelWidth = sheet.getColumnWidth(cell.getColumnIndex()); colRef = CellReference.convertNumToColString(cell.getColumnIndex()); int rowIndex = getCell().getRowIndex(); int rowRef = rowIndex + 1; absoluteRef = colRef + rowRef; verticalRange = new SimpleRange(rowIndex, rowIndex); horizontalAlignment = Alignment.LEFT; verticalAlignment = getCell().getCellStyle().getVerticalAlignment(); }
public XLSXCellNode(XSSFSheet sheet,XSSFCell cell,int index,XLSXExpression expression) { super(sheet,cell,expression); assert cell != null : "null cell" ; if(cell.getCTCell().isSetF()){ formulaStringValue = cell.getCTCell().getF().getStringValue(); } colRef = CellReference.convertNumToColString(index); int rowRef = getCell().getRowIndex() + 1; absoluteRef = colRef + rowRef; if(cell.getCTCell().isSetS()){ s = cell.getCTCell().getS(); } workbookPr = getSheet().getWorkbook().getCTWorkbook().getWorkbookPr(); comment = cell.getCellComment(); if(comment != null){ commnetExpr = CellExpressionParser.parseExpression(comment.getString().getString()); } }