My data is stored in a format(look down): [-] means a blank cell, on the right may be only 10 columns, after the space. Something like this:
[string0] [-] [string1] [string2] [string3] .. [string10] [-]
How to change this code for:
obtain full string, for EACH row fullString = [-] [string1] [string2] [string3] .. [string10] [-]. StringBuilder? Or how?
//Get first sheet from the workbook HSSFSheet sheet = workbook.getSheetAt(0); //Iterate through each rows from first sheet Iterator<Row> rowIterator = sheet.iterator(); while(rowIterator.hasNext()) { Row row = rowIterator.next(); //For each row, iterate through each columns Iterator<Cell> cellIterator = row.cellIterator(); while(cellIterator.hasNext()) { Cell cell = cellIterator.next(); switch(cell.getCellType()) { case Cell.CELL_TYPE_STRING: System.out.print(cell.getStringCellValue() + "\t\t"); list1.add(cell.getStringCellValue()); break; } } System.out.println(""); } file.close(); FileOutputStream out = new FileOutputStream("C:\\Users\\student3\\"+sfilename+".xls"); workbook.write(out); out.close();
External Link: Busy Developers' Guide to HSSF and XSSF Features
Here is an example that should work.
Maven Dependencies:
Code: