/** * Returns the name of this sheet * * @return the name of this sheet */ @Override public String getSheetName() { return _sh.getSheetName(); }
/** * Get sheet with the given name (case insensitive match) * * @param name of the sheet * @return XSSFSheet with the name provided or <code>null</code> if it does not exist */ @Override public XSSFSheet getSheet(String name) { for (XSSFSheet sheet : sheets) { if (name.equalsIgnoreCase(sheet.getSheetName())) { return sheet; } } return null; }
/** * Returns the index of the sheet by his name (case insensitive match) * * @param name the sheet name * @return index of the sheet (0 based) or <tt>-1</tt> if not found */ @Override public int getSheetIndex(String name) { int idx = 0; for (XSSFSheet sh : sheets) { if (name.equalsIgnoreCase(sh.getSheetName())) { return idx; } idx++; } return -1; }
protected XSSFSheet readSheet(int index, String name) { XSSFSheet sheet = workbook.getSheetAt(index); if (!sheet.getSheetName().equals(name)) { throw new IllegalArgumentException("The sheet (" + sheet.getSheetName() + ") at index (" + index + ") is expected to have another name (" + name + ")"); } return sheet; }
/** * @since 3.15 beta 2 */ public String getSheetName() { return getXSSFSheet().getSheetName(); }
/** * Get the sheet name * * @param sheetIx Number * @return Sheet name */ @Override public String getSheetName(int sheetIx) { validateSheetIndex(sheetIx); return sheets.get(sheetIx).getSheetName(); }
protected String currentPosition() { return "Sheet (" + currentSheet.getSheetName() + ") cell (" + (currentRowNumber + 1) + CellReference.convertNumToColString(currentColumnNumber) + ")"; }
@Override public String getDataRangeReference() { return cellRangeAddress.formatAsString(sheet.getSheetName(), true); }
/** * @param range * @return * @since POI 4.0.0 */ public String formatRange(CellRangeAddress range) { final XSSFSheet sheet = getSheet(); return (sheet == null) ? null : range.formatAsString(sheet.getSheetName(), true); }
/** * Create a pivot table using the AreaReference range, at the given position. * If the source reference contains a sheet name, that sheet is used, otherwise this sheet is assumed as the source sheet. * @param source location of pivot data * @param position A reference to the top left cell where the pivot table will start * @return The pivot table */ @Beta public XSSFPivotTable createPivotTable(AreaReference source, CellReference position){ final String sourceSheetName = source.getFirstCell().getSheetName(); if(sourceSheetName != null && !sourceSheetName.equalsIgnoreCase(this.getSheetName())) { final XSSFSheet sourceSheet = getWorkbook().getSheet(sourceSheetName); return createPivotTable(source, position, sourceSheet); } return createPivotTable(source, position, this); }
/** * set sheet title in excel file * * @param title * title of sheet * @param column * column index * @return return cell reference * @since POI 4.0.0 */ public CellReference setSheetTitle(String title, int column) { XSSFSheet sheet = getSheet(); XSSFRow row = this.getRow(sheet, 0); XSSFCell cell = this.getCell(row, column); cell.setCellValue(title); this.updateSheetTable(sheet.getTables().get(0).getCTTable(), title, column); return new CellReference(sheet.getSheetName(), 0, column, true, true); }
XSSFSheet sheet = (XSSFSheet) sh; if(includeSheetNames) { text.append(sheet.getSheetName()).append("\n");
XSSFCell cell = singleXmlCell.getReferencedCell(); logger.log(POILogger.DEBUG, "Setting '" + textContent + "' to cell " + cell.getColumnIndex() + "-" + cell.getRowIndex() + " in sheet " + cell.getSheet().getSheetName()); setCellValue(textContent, cell, xmlDataType); + table.getXSSFSheet().getSheetName()); setCellValue(value, cell, xmlColumnPr.getXmlDataType());
if (areaSheetName != null && !areaSheetName.equals(getXSSFSheet().getSheetName())) {
/** * Shifts columns between startColumn and endColumn n number of columns. * If you use a negative number, it will shift columns left. * Code ensures that columns don't wrap around * * @param startColumn the column to start shifting * @param endColumn the column to end shifting * @param n length of the shifting step */ @Override public void shiftColumns(int startColumn, int endColumn, final int n) { XSSFVMLDrawing vml = getVMLDrawing(false); shiftCommentsForColumns(vml, startColumn, endColumn, n); FormulaShifter formulaShifter = FormulaShifter.createForColumnShift(this.getWorkbook().getSheetIndex(this), this.getSheetName(), startColumn, endColumn, n, SpreadsheetVersion.EXCEL2007); XSSFColumnShifter columnShifter = new XSSFColumnShifter(this); columnShifter.shiftColumns(startColumn, endColumn, n); columnShifter.shiftMergedRegions(startColumn, startColumn, n); columnShifter.updateFormulas(formulaShifter); columnShifter.updateConditionalFormatting(formulaShifter); columnShifter.updateHyperlinks(formulaShifter); columnShifter.updateNamedRanges(formulaShifter); rebuildRows(); }
String testSheetName = currentSheet.getSheetName();
String srcName = srcSheet.getSheetName(); newName = getUniqueSheetName(srcName); } else {
File file = new File("D:/temp/test.xlsx"); FileInputStream fis = new FileInputStream(file); XSSFWorkbook wb = new XSSFWorkbook(fis); XSSFSheet sh = wb.getSheet("Hola"); System.out.println(sh.getLastRowNum()); System.out.println("Name: "+sh.getSheetName()); Row row = sh.getRow(1); System.out.println(row.getRowNum()); System.out.println("Val: "+sh.getRow(1).getCell(1).getStringCellValue());
@Override public XSSFAutoFilter setAutoFilter(CellRangeAddress range) { CTAutoFilter af = worksheet.getAutoFilter(); if(af == null) { af = worksheet.addNewAutoFilter(); } CellRangeAddress norm = new CellRangeAddress(range.getFirstRow(), range.getLastRow(), range.getFirstColumn(), range.getLastColumn()); String ref = norm.formatAsString(); af.setRef(ref); XSSFWorkbook wb = getWorkbook(); int sheetIndex = getWorkbook().getSheetIndex(this); XSSFName name = wb.getBuiltInName(XSSFName.BUILTIN_FILTER_DB, sheetIndex); if (name == null) { name = wb.createBuiltInName(XSSFName.BUILTIN_FILTER_DB, sheetIndex); } name.getCTName().setHidden(true); CellReference r1 = new CellReference(getSheetName(), range.getFirstRow(), range.getFirstColumn(), true, true); CellReference r2 = new CellReference(null, range.getLastRow(), range.getLastColumn(), true, true); String fmla = r1.formatAsString() + ":" + r2.formatAsString(); name.setRefersToFormula(fmla); return new XSSFAutoFilter(this); }
/** * @since 3.15 beta 2 */ public String getSheetName() { return getXSSFSheet().getSheetName(); }