protected boolean hasSheet(String sheetName) { return workbook.getSheet(sheetName) != null; }
/** * Get sheet with the given name * * @param name of the sheet * @return Sheet with the name provided or <code>null</code> if it does not exist */ @Override public SXSSFSheet getSheet(String name) { return getSXSSFSheet(_wb.getSheet(name)); }
/** * Create an XSSFSheet for this workbook, adds it to the sheets and returns * the high level representation. Use this to create new sheets. * * @return XSSFSheet representing the new sheet. */ @Override public XSSFSheet createSheet() { String sheetname = "Sheet" + (sheets.size()); int idx = 0; while(getSheet(sheetname) != null) { sheetname = "Sheet" + idx; idx++; } return createSheet(sheetname); }
protected void nextSheet(String sheetName) { currentSheet = workbook.getSheet(sheetName); if (currentSheet == null) { throw new IllegalStateException("The workbook does not contain a sheet with name (" + sheetName + ")."); } currentRowIterator = currentSheet.rowIterator(); if (currentRowIterator == null) { throw new IllegalStateException(currentPosition() + ": The sheet has no rows."); } currentRowNumber = -1; }
/** * Create a pivot table using the Name 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(Name source, CellReference position) { return createPivotTable(source, position, getWorkbook().getSheet(source.getSheetName())); }
/** * 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); }
/** * Create a pivot table using the Table, at the given position. * Tables are required to have a sheet reference, so no additional logic around reference sheet is needed. * @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(final Table source, CellReference position) { return createPivotTable(position, getWorkbook().getSheet(source.getSheetName()), wsSource -> wsSource.setName(source.getName())); }
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());
public class SO{ public static void main(String[] args) { try { FileInputStream is = new FileInputStream(new File("D:\\Users\\user2777005\\Desktop\\bob.xlsx")); XSSFWorkbook wb = new XSSFWorkbook(is); String header = "123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789"; Sheet sheet = wb.getSheet("Sheet1"); sheet.setColumnWidth(0, 18000); Row row = sheet.createRow(0); Cell cell = row.createCell(0); if(header.length() > 50){ //Length of String for my test sheet.setColumnWidth(0, 18000); //Set column width, you'll probably want to tweak the second int CellStyle style = wb.createCellStyle(); //Create new style style.setWrapText(true); //Set wordwrap cell.setCellStyle(style); //Apply style to cell cell.setCellValue(header); //Write header } wb.write(new FileOutputStream(new File("D:\\Users\\user2777005\\Desktop\\bob.xlsx"))); } catch (IOException e) { e.printStackTrace(); } } }
Sheet templateSheet = ((XSSFWorkbook) data.wb).getSheet( data.realSheetname ); int currentRowNum = templateSheet.getLastRowNum(); SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook( (XSSFWorkbook) data.wb, 100 );
FileInputStream file = new FileInputStream(new File("C:\\Users\\user\\Desktop\\filet.xlsm")); System.out.println("found file"); XSSFWorkbook workbook = new XSSFWorkbook(file); System.out.println("in workbook"); XSSFSheet sheet = workbook.getSheet("Shipments"); System.out.println("got sheet");
public static XSSFSheet loadSheet(XSSFWorkbook workbook, String sheetName) throws ExcelException { XSSFSheet sheet = workbook.getSheet(sheetName); if (sheet == null) { throw new ExcelException("Sheet name does not exist in the workbook."); } return sheet; }
/** * Get sheet with the given name * * @param name of the sheet * @return Sheet with the name provided or <code>null</code> if it does not exist */ public Sheet getSheet(String name) { return getSXSSFSheet(_wb.getSheet(name)); }
public static boolean createSheetIfNotExists(XSSFWorkbook workbook, String sheet) { boolean created = false; XSSFSheet xssfSheet = workbook.getSheet(sheet); if (xssfSheet == null) { workbook.createSheet(sheet); created = true; } return created; }
/** * Get sheet with the given name * * @param name of the sheet * @return Sheet with the name provided or <code>null</code> if it does not exist */ @Override public SXSSFSheet getSheet(String name) { return getSXSSFSheet(_wb.getSheet(name)); }
XSSFWorkbook workbook = null; try { workbook = new XSSFWorkbook(new FileInputStream(fileName)); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } XSSFSheet sheet = workbook.getSheet(sheetName); System.out.println(sheet.getLastRowNum());
protected void nextSheet(String sheetName) { currentSheet = workbook.getSheet(sheetName); if (currentSheet == null) { throw new IllegalStateException("The workbook does not contain a sheet with name (" + sheetName + ")."); } currentRowIterator = currentSheet.rowIterator(); if (currentRowIterator == null) { throw new IllegalStateException(currentPosition() + ": The sheet has no rows."); } currentRowNumber = -1; }
public static void appendToColInRow(XSSFWorkbook workbook, String sheetName, Row row, int columnNumber, Map<String, Object> data) throws ExcelException { Cell cell = row.getCell(columnNumber); Excel self = new Excel(); XSSFSheet sheet = workbook.getSheet(sheetName); if (cell == null) { self.LOG.debug("cell was null, creating it in the row(" + row.getRowNum() + "): " + data); cell = row.createCell(columnNumber); } writeCell(workbook, sheet, cell, columnNumber, data); }
/** * Create a pivot table using the Name 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(Name source, CellReference position) { return createPivotTable(source, position, getWorkbook().getSheet(source.getSheetName())); }
/** * Create a pivot table using the Table, at the given position. * Tables are required to have a sheet reference, so no additional logic around reference sheet is needed. * @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(final Table source, CellReference position) { return createPivotTable(position, getWorkbook().getSheet(source.getSheetName()), wsSource -> wsSource.setName(source.getName())); }