@Override public int getColumnIndex() { return _cell.getColumnIndex(); } @Override
/** * Moves the supplied cell to a new column, which * must not already have a cell there! * @param cell The cell to move * @param newColumn The new column number (0 based) */ public void moveCell(HSSFCell cell, short newColumn) { // Ensure the destination is free if(cells.length > newColumn && cells[newColumn] != null) { throw new IllegalArgumentException("Asked to move cell to column " + newColumn + " but there's already a cell there"); } // Check it's one of ours if(! cells[cell.getColumnIndex()].equals(cell)) { throw new IllegalArgumentException("Asked to move a cell, but it didn't belong to our row"); } // Move the cell to the new position // (Don't remove the records though) removeCell(cell, false); cell.updateCellNum(newColumn); addCell(cell); }
private void removeCell(HSSFCell cell, boolean alsoRemoveRecords) { int column=cell.getColumnIndex(); if(column < 0) { throw new RuntimeException("Negative cell indexes not allowed"); } if(column >= cells.length || cell != cells[column]) { throw new RuntimeException("Specified cell is not from this row"); } if(cell.isPartOfArrayFormulaGroup()){ cell.notifyArrayFormulaChanging(); } cells[column]=null; if(alsoRemoveRecords) { CellValueRecordInterface cval = cell.getCellValueRecord(); sheet.getSheet().removeValueRecord(getRowNum(), cval); } if (cell.getColumnIndex()+1 == row.getLastCol()) { row.setLastCol(calculateNewLastCellPlusOne(row.getLastCol())); } if (cell.getColumnIndex() == row.getFirstCol()) { row.setFirstCol(calculateNewFirstCell(row.getFirstCol())); } }
/** * used internally to add a cell. */ private void addCell(HSSFCell cell) { int column=cell.getColumnIndex(); // re-allocate cells array as required. if(column>=cells.length) { HSSFCell[] oldCells=cells; // New size based on the same logic as ArrayList int newSize=oldCells.length*3/2+1; if(newSize<column+1) { newSize=column+INITIAL_CAPACITY; } cells=new HSSFCell[newSize]; System.arraycopy(oldCells,0,cells,0,oldCells.length); } cells[column]=cell; // fix up firstCol and lastCol indexes if (row.isEmpty() || column < row.getFirstCol()) { row.setFirstCol((short)column); } if (row.isEmpty() || column >= row.getLastCol()) { row.setLastCol((short) (column+1)); // +1 -> for one past the last index } }
/** * @deprecated (Oct 2008) use {@link #getColumnIndex()} */ public short getCellNum() { return (short) getColumnIndex(); }
/** * @deprecated (Oct 2008) use {@link #getColumnIndex()} */ public short getCellNum() { return (short) getColumnIndex(); }
@Override public int getColumnIndex() { return _cell.getColumnIndex(); } @Override
public int getColumnIndex() { return _cell.getColumnIndex(); } public int getErrorCellValue() {
public int getColumnIndex() { return _cell.getColumnIndex(); } public int getErrorCellValue() {
Map<String,Integer> headers = new TreeMap<String,Integer>(); for (Cell _cell : row) { HSSFCell cell = (HSSFCell) _cell; // iterator returns Cell, we need to cast it manually HSSFRichTextString richTextString = cell.getRichStringCellValue (); headers.put(richTextString.getString(), cell.getColumnIndex()); }
@Override public void apply() { for (DataObject dataObject : data) { dataObject.resultCell.getSheet().autoSizeColumn(dataObject.resultCell.getColumnIndex()); } } }
@Override public void apply() { for (DataObject dataObject : data) { dataObject.resultCell.getSheet().setColumnWidth(dataObject.resultCell.getColumnIndex(), dataObject.templateCell.getSheet().getColumnWidth(dataObject.templateCell.getColumnIndex())); } } }
@Override public void apply() { for (DataObject dataObject : data) { dataObject.resultCell.getSheet().autoSizeColumn(dataObject.resultCell.getColumnIndex()); } } }
@Override public void apply() { for (DataObject dataObject : data) { dataObject.resultCell.getSheet().setColumnWidth(dataObject.resultCell.getColumnIndex(), dataObject.templateCell.getSheet().getColumnWidth(dataObject.templateCell.getColumnIndex())); } } }
Map<String, Integer> map = new HashMap<String,Integer>(); //Create map HSSFRow row = sheet.getRow(0); //Get first row //following is boilerplate from the java doc short minColIx = row.getFirstCellNum(); //get the first column index for a row short maxColIx = row.getLastCellNum(); //get the last column index for a row for(short colIx=minColIx; colIx<maxColIx; colIx++) { //loop from first to last index HSSFCell cell = row.getCell(colIx); //get the cell map.put(cell.getStringCellValue(),cell.getColumnIndex()) //add the cell contents (name of column) and cell index to the map }
/** * Make a row span the width of the table. * @param model The table model representing the rendered table. */ private void rowSpanTable(TableModel model) { this.sheet.addMergedRegion(this.getMergeCellsRegion( this.currentCell.getColumnIndex(), (model.getNumberOfColumns() - 1))); }
/** * Make a row span the width of the table. * @param model The table model representing the rendered table. */ private void rowSpanTable(TableModel model) { this.sheet.addMergedRegion(this.getMergeCellsRegion(this.currentCell.getColumnIndex(), (model .getNumberOfColumns() - 1))); }
private static void createTilte(HSSFWorkbook wb, HSSFSheet sheet) { HSSFRow titleRow = sheet.getRow(0); HSSFCell cell = titleRow.createCell(0); cell.setCellStyle(createTilteStyle(wb)); cell.setCellValue("KEY"); sheet.setColumnWidth(cell.getColumnIndex(), (40 * 256)); }
private static void addLang2Tilte(HSSFWorkbook wb, HSSFSheet sheet, String lang) { HSSFRow titleRow = sheet.getRow(0); HSSFCell lastCell = titleRow.getCell((int)titleRow.getLastCellNum() - 1); if (lang.equals(lastCell.getStringCellValue())) { // language column already exists return; } HSSFCell cell = titleRow.createCell((int)titleRow.getLastCellNum()); cell.setCellStyle(createTilteStyle(wb)); cell.setCellValue(lang); sheet.setColumnWidth(cell.getColumnIndex(), (60 * 256)); }
private void fixNeighbourCellBorders(HSSFCellStyle cellStyle, HSSFCell resultCell) { HSSFSheet sheet = resultCell.getRow().getSheet(); // disable neighboring cells border int columnIndex = resultCell.getColumnIndex(); int rowIndex = resultCell.getRowIndex(); // fix left border fixLeftBorder(cellStyle, sheet, columnIndex, resultCell); // fix right border fixRightBorder(cellStyle, sheet, columnIndex, resultCell); // fix up border fixUpBorder(cellStyle, sheet, columnIndex, rowIndex, resultCell); // fix down border fixDownBorder(cellStyle, sheet, columnIndex, rowIndex, resultCell); }