protected boolean currentRowIsEmpty() { if (currentRow.getPhysicalNumberOfCells() == 0) { return true; } for (Cell cell : currentRow) { if (cell.getCellTypeEnum() == CellType.STRING) { if (!cell.getStringCellValue().isEmpty()) { return false; } } else if (cell.getCellTypeEnum() != CellType.BLANK) { return false; } } return true; }
private void writeDaySheet(LocalDate day, List<Timeslot> timeslotList, List<Talk> talkList) { nextSheet(DAY_FORMATTER.format(day), 1, 1, true); nextRow(); nextHeaderCell(DAY_FORMATTER.format(day)); writeTimeslotHoursVertically(timeslotList); List<Room> dayRoomList = talkList.stream().map(Talk::getRoom).distinct().collect(toList()); dayRoomList.sort(Comparator.comparing(Room::getName)); for (Room room : dayRoomList) { currentColumnNumber++; currentRowNumber = -1; nextCellVertically().setCellValue(room.getName()); List<Talk> roomTalkList = talkList.stream() .filter(talk -> talk.getRoom() == room) .collect(toList()); writeRoomTalks(timeslotList, room, roomTalkList); } currentSheet.autoSizeColumn(0); for (int i = 1; i < currentSheet.getRow(0).getPhysicalNumberOfCells(); i++) { currentSheet.setColumnWidth(i, 15 * 256); } }
XSSFWorkbook wb = new XSSFWorkbook(new File("MyExcel.xls")); XSSFSheet sheet = wb.getSheetAt(0); DataFormatter formatter = new DataFormatter(); for (Iterator iterator = sheet.rowIterator(); iterator.hasNext();) { XSSFRow row = (XSSFRow) iterator.next(); for (int i = 0; i < row.getPhysicalNumberOfCells(); i++) { XSSFCell cell = row.getCell(i); System.out.println(formatter .formatCellValue(cell)); } }
private int buildMaxColumn(XSSFSheet sheet){ int rowCount=sheet.getPhysicalNumberOfRows(); int maxColumnCount=0; for(int i=0;i<rowCount;i++){ XSSFRow row=sheet.getRow(i); if(row==null){ continue; } int columnCount=row.getPhysicalNumberOfCells(); if(columnCount>maxColumnCount){ maxColumnCount=columnCount; } } return maxColumnCount; }
List<String> cellValue = new ArrayList<String>(); XSSFWorkbook wb = new XSSFWorkbook(new File("MyExcel.xls")); XSSFSheet sheet = wb.getSheetAt(0); DataFormatter formatter = new DataFormatter(); for (Iterator<Row> iterator = sheet.rowIterator(); iterator.hasNext();) { XSSFRow row = (XSSFRow) iterator.next(); for (int i = 0; i < row.getPhysicalNumberOfCells(); i++) { XSSFCell cell = row.getCell(i); cellValue.add(formatter.formatCellValue(cell)); }
protected boolean currentRowIsEmpty() { if (currentRow.getPhysicalNumberOfCells() == 0) { return true; } for (Cell cell : currentRow) { if (cell.getCellTypeEnum() == CellType.STRING) { if (!cell.getStringCellValue().isEmpty()) { return false; } } else if (cell.getCellTypeEnum() != CellType.BLANK) { return false; } } return true; }
@Override protected void endSerialize( RootNode rootNode, OutputStream outputStream ) throws Exception { int columns = sheet.getRow( 0 ).getPhysicalNumberOfCells(); for ( int i = 0; i < columns; i++ ) { sheet.autoSizeColumn( i ); } workbook.write( outputStream ); }
private void writeDaySheet(LocalDate day, List<Timeslot> timeslotList, List<Talk> talkList) { nextSheet(DAY_FORMATTER.format(day), 1, 1, true); nextRow(); nextHeaderCell(DAY_FORMATTER.format(day)); writeTimeslotHoursVertically(timeslotList); List<Room> dayRoomList = talkList.stream().map(Talk::getRoom).distinct().collect(toList()); dayRoomList.sort(Comparator.comparing(Room::getName)); for (Room room : dayRoomList) { currentColumnNumber++; currentRowNumber = -1; nextCellVertically().setCellValue(room.getName()); List<Talk> roomTalkList = talkList.stream() .filter(talk -> talk.getRoom() == room) .collect(toList()); writeRoomTalks(timeslotList, room, roomTalkList); } currentSheet.autoSizeColumn(0); for (int i = 1; i < currentSheet.getRow(0).getPhysicalNumberOfCells(); i++) { currentSheet.setColumnWidth(i, 15 * 256); } }
if (row != null){ Map<String,String> map = new TreeMap<String,String>(); int cells = title.getPhysicalNumberOfCells();
XSSFRow row = sheet.createRow(sheet.getPhysicalNumberOfRows()); for(String dataCell : dataRow){ XSSFCell cell = row.createCell(row.getPhysicalNumberOfCells()); cell.setCellValue(dataCell);