List of usage examples for org.apache.poi.xssf.usermodel XSSFWorkbook XSSFWorkbook
public XSSFWorkbook(PackagePart part) throws IOException
From source file:ReadSheet2.java
public HashMap readTable2(String path) throws IOException { HashMap<String, Object> table2part1 = new HashMap(); HashMap<String, Object> table2part2 = new HashMap(); HashMap<String, Object> table2 = new HashMap(); HashMap<String, Object> conformation = new HashMap(); HashMap<String, Object> verification = new HashMap(); FileInputStream fs = new FileInputStream(new File(path)); XSSFWorkbook wb = new XSSFWorkbook(fs); XSSFSheet sheet = wb.getSheetAt(2);/*from w ww. ja v a 2 s . co m*/ /* Read Table 1 of the sheet 1 */ //String [] headerArray1 = {"MARKER #","IM #","FABRIC COLOR","Fabric Face","SPECIAL NOTES"}; //String [] headerArray2 = {"MARKER A","MARKER B","MARKER C","MARKER D","MARKER E","MARKER F"}; //int rowIndexOfHeaderStart, int columnIndexOfHeaders, String[] headerArray int[] rawHeaders = reader.columnHeaderValidator(sheet, 9, sheet2FabricDetailsColumns); int[] rawheaders2 = reader.rowHeaderValidator(sheet, 9, 0, sheet2FabricDetailsRows); // table2part1 = reader.readColumnAndRowHeaderTable(sheet, 9, 0, rawHeaders, 9, 13, rawheaders2); table2.put("Marker", table2part1); //---------------------------- conformation.put(reader.getValue(sheet.getRow(14).getCell(0)).toString(), reader.getValue(sheet.getRow(14).getCell(3))); String temp = reader.getValue(sheet.getRow(14).getCell(10)).toString(); String key = temp.substring(0, 4); String value = temp.substring(4); if (temp.length() > 4) { conformation.put(key, value); } else conformation.put(temp, ""); conformation.put(reader.getValue(sheet.getRow(14).getCell(15)).toString(), reader.getValue(sheet.getRow(14).getCell(17))); table2.put("conformation", conformation); //-------------------------------- verification.put(reader.getValue(sheet.getRow(15).getCell(0)).toString(), reader.getValue(sheet.getRow(15).getCell(3))); String temp1 = reader.getValue(sheet.getRow(15).getCell(10)).toString(); String key1 = temp1.substring(0, 4); String value1 = temp1.substring(4); if (temp1.length() > 4) { verification.put(key1, value1); } else verification.put(temp1, ""); verification.put(reader.getValue(sheet.getRow(15).getCell(15)).toString(), reader.getValue(sheet.getRow(15).getCell(17))); table2.put("verification", verification); return table2; }
From source file:ReadSheet2.java
public HashMap readTable3(String path) throws IOException { HashMap<String, Object> table3part1 = new HashMap(); HashMap<String, Object> table3part2 = new HashMap(); HashMap<String, Object> table3 = new HashMap(); HashMap<String, Object> conformation = new HashMap(); HashMap<String, Object> verification = new HashMap(); FileInputStream fs = new FileInputStream(new File(path)); XSSFWorkbook wb = new XSSFWorkbook(fs); XSSFSheet sheet = wb.getSheetAt(2);// www .j a va 2 s . c o m /* Read Table 1 of the sheet 1 */ //String [] headerArray1 = {"SIZE","RATIO","NO OF PLIES","TOTAL CUT QTY","REQUIRED QTY"}; //String [] headerArray2 = {"XS","S","M","L","XL" }; //int rowIndexOfHeaderStart, int columnIndexOfHeaders, String[] headerArray int[] rawHeaders = reader.columnHeaderValidator(sheet, 19, sheet2CuttingInfoColumns); int[] rawheaders2 = reader.rowHeaderValidator(sheet, 19, 0, sheet2CuttingInfoRows); // table3part1 = reader.readColumnAndRowHeaderTable(sheet, 19, 0, rawHeaders, 19, 23, rawheaders2); table3.put("cutting metrix", table3part1); //---------------------------- String temp = reader.getValue(sheet.getRow(17).getCell(0)).toString(); String key = temp.substring(0, 14); String value = temp.substring(14); if (temp.length() > 13) { table3.put(key, value); } else table3.put(temp, ""); String temp1 = reader.getValue(sheet.getRow(18).getCell(0)).toString(); String key1 = temp1.substring(0, 14); String value1 = temp1.substring(14); if (temp1.length() > 15) { table3.put(key1, value1); } else table3.put(temp1, ""); String temp2 = reader.getValue(sheet.getRow(17).getCell(15)).toString(); String key2 = temp2.substring(0, 10); String value2 = temp2.substring(10); if (temp2.length() > 10) { table3.put(key2, value2); } else table3.put(temp2, ""); String temp3 = reader.getValue(sheet.getRow(18).getCell(15)).toString(); String key3 = temp3.substring(0, 10); String value3 = temp3.substring(10); if (temp3.length() > 10) { table3.put(key3, value3); } else table3.put(temp3, ""); return table3; }
From source file:ReadSheet2.java
public HashMap readTable4(String path) throws IOException { HashMap<String, Object> table4 = new HashMap(); HashMap<String, Object> cutverification = new HashMap(); HashMap<String, Object> cpiverification = new HashMap(); FileInputStream fs = new FileInputStream(new File(path)); XSSFWorkbook wb = new XSSFWorkbook(fs); XSSFSheet sheet = wb.getSheetAt(2);//from w ww . j a va2s .co m String temp = reader.getValue(sheet.getRow(26).getCell(0)).toString(); String key = temp.substring(0, 13); String value = temp.substring(13); if (temp.length() > 13) { cpiverification.put(key, value); } else cpiverification.put(temp, ""); String temp1 = reader.getValue(sheet.getRow(27).getCell(0)).toString(); String key1 = temp1.substring(0, 10); String value1 = temp1.substring(10); if (temp1.length() > 10) { cpiverification.put(key1, value1); } else cpiverification.put(temp1, ""); table4.put("CPI VERIFICATION", cpiverification); //------------------------------------ String temp2 = reader.getValue(sheet.getRow(26).getCell(16)).toString(); String key2 = temp2.substring(0, 22); String value2 = temp2.substring(22); if (temp2.length() > 22) { cutverification.put(key2, value2); } else cutverification.put(temp2, ""); String temp3 = reader.getValue(sheet.getRow(27).getCell(16)).toString(); String key3 = temp3.substring(0, 10); String value3 = temp3.substring(10); if (temp3.length() > 10) { cutverification.put(key3, value3); } else cutverification.put(temp3, ""); table4.put("Cut BANK VERIFICATION", cutverification); return table4; }
From source file:TaskFetcher.java
static HashMap<String, String> fetchActiveTasks(String username, String excel_path) { HashMap<String, String> activetasks = new HashMap<String, String>(); FileInputStream file = null;/*from w w w .java 2 s .c o m*/ try { file = new FileInputStream(new File(excel_path)); } catch (FileNotFoundException ex) { Logger.getLogger(TaskFetcher.class.getName()).log(Level.SEVERE, null, ex); } //Create Workbook instance holding reference to .xlsx file XSSFWorkbook workbook = null; try { workbook = new XSSFWorkbook(file); } catch (IOException ex) { Logger.getLogger(TaskFetcher.class.getName()).log(Level.SEVERE, null, ex); } //Get first/desired sheet from the workbook XSSFSheet sheet = workbook.getSheetAt(0); Iterator<Row> rowIterator = sheet.iterator(); if (rowIterator.hasNext()) rowIterator.next(); //skipping the first row of heading while (rowIterator.hasNext()) //loop over all entries in the excel sheet { Row row = rowIterator.next(); Cell cell = row.getCell(0); if (username.equalsIgnoreCase(cell.getStringCellValue())) { String task; String status; String totTimeString = null; String latestTimeStamp; double totTime; task = row.getCell(1).getStringCellValue(); status = row.getCell(2).getStringCellValue(); latestTimeStamp = row.getCell(3).getStringCellValue(); if (status.equalsIgnoreCase("Paused") || status.equalsIgnoreCase("Deferred")) { if (row.getCell(4) != null) totTimeString = row.getCell(4).getStringCellValue(); } else if (status.equalsIgnoreCase("In-Progress")) { if (row.getCell(4) != null) totTimeString = row.getCell(4).getStringCellValue(); if (totTimeString != null) { totTime = Double.parseDouble(totTimeString); } else { totTime = 0; } DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss"); Date currentTimestamp = new Date(); Date latestTimeStampObj = null; df.format(currentTimestamp); try { latestTimeStampObj = df.parse(latestTimeStamp); } catch (ParseException ex) { Logger.getLogger(TaskFetcher.class.getName()).log(Level.SEVERE, null, ex); } long timeDifference = currentTimestamp.getTime() - latestTimeStampObj.getTime(); long divisor = 60 * 60 * 1000; double diffHours = ((double) timeDifference / (double) divisor); totTime += diffHours; totTimeString = String.valueOf(totTime); } if (status != null && !status.equalsIgnoreCase("completed") && task != null && totTimeString != null) { activetasks.put(task, status + ":" + totTimeString); } } } try { workbook.close(); } catch (IOException ex) { Logger.getLogger(TaskFetcher.class.getName()).log(Level.SEVERE, null, ex); } return activetasks; }
From source file:TaskFetcher.java
static HashMap<String, String> fetchAllTasks(String username, String excel_path) { HashMap<String, String> alltasks = new HashMap<String, String>(); FileInputStream file = null;//from w w w.j av a 2s .c o m try { file = new FileInputStream(new File(excel_path)); } catch (FileNotFoundException ex) { Logger.getLogger(TaskFetcher.class.getName()).log(Level.SEVERE, null, ex); } //Create Workbook instance holding reference to .xlsx file XSSFWorkbook workbook = null; try { workbook = new XSSFWorkbook(file); } catch (IOException ex) { Logger.getLogger(TaskFetcher.class.getName()).log(Level.SEVERE, null, ex); } //Get first sheet from the workbook XSSFSheet sheet = workbook.getSheetAt(1); Iterator<Row> rowIterator = sheet.iterator(); if (rowIterator.hasNext()) rowIterator.next(); //skipping the first row of heading while (rowIterator.hasNext()) //loop over all entries in the excel sheet { Row row = rowIterator.next(); Cell cell = row.getCell(0); if (username.equalsIgnoreCase(cell.getStringCellValue())) { String task; String status; String timestamp; String comments; task = row.getCell(1).getStringCellValue(); status = row.getCell(2).getStringCellValue(); timestamp = row.getCell(3).getStringCellValue(); comments = row.getCell(4).getStringCellValue(); alltasks.put(timestamp, task + ":" + status + ":" + comments); } } try { workbook.close(); } catch (IOException ex) { Logger.getLogger(TaskFetcher.class.getName()).log(Level.SEVERE, null, ex); } return alltasks; }
From source file:accounts.ExcelUtils.java
License:Apache License
public Map<String, Map<TRId, TR>> processAllSheets(String filename, Map<String, BankAccount> baMap, String accountName) throws IOException, DBException { Map<String, Map<TRId, TR>> excelTrMap = new TreeMap<>(); FileInputStream file = new FileInputStream(new File(filename)); // Get the workbook instance for XLS file XSSFWorkbook workbook = new XSSFWorkbook(file); for (int i = 0; i < workbook.getNumberOfSheets(); i++) { XSSFSheet sheet = workbook.getSheetAt(i); String sheetName = workbook.getSheetName(i); if ("RentalSummary".equalsIgnoreCase(sheetName) || "CompanySummary".equalsIgnoreCase(sheetName) || "PersonalSummary".equalsIgnoreCase(sheetName)) { continue; }/*from w ww. j av a2 s . c o m*/ if (accountName != null && !accountName.equalsIgnoreCase(sheetName)) { continue; } Map<TRId, TR> mapTr = new HashMap<>(); excelTrMap.put(sheetName, mapTr); System.out.println("Processing sheet: " + sheetName); BankAccount ba = baMap.get(sheetName); if (ba == null) { throw new IOException("Unknown bank account name in excel=" + sheetName); } for (int rownum = 1; rownum <= sheet.getLastRowNum(); rownum++) { Row row = sheet.getRow(rownum); // Get iterator to all cells of current row TR tr = DBFactory.inst().createCorrespondingTRObj(ba); tr.setDate(row.getCell(0).getDateCellValue()); tr.setDescription(row.getCell(1).getStringCellValue()); tr.setDebit((float) row.getCell(2).getNumericCellValue()); tr.setComment(row.getCell(3).getStringCellValue()); tr.setTrType(row.getCell(4).getStringCellValue()); tr.setTaxCategory(row.getCell(5).getStringCellValue()); tr.setProperty(row.getCell(6).getStringCellValue()); tr.setOtherEntity(row.getCell(7).getStringCellValue()); String locked = row.getCell(8).getStringCellValue(); tr.setLocked("YES".equalsIgnoreCase(locked)); tr.setTrId(); mapTr.put(tr.getTrId(), tr); } } return excelTrMap; }
From source file:accounts.ExcelUtils.java
License:Apache License
public Map<String, Map<TRId, TR>> processAllSheets(String filename) throws IOException { Map<String, Map<TRId, TR>> excelTrMap = new TreeMap<>(); FileInputStream file = new FileInputStream(new File(filename)); // Get the workbook instance for XLS file XSSFWorkbook workbook = new XSSFWorkbook(file); for (int i = 0; i < workbook.getNumberOfSheets(); i++) { XSSFSheet sheet = workbook.getSheetAt(i); String sheetName = workbook.getSheetName(i); Map<TRId, TR> mapTr = new HashMap<>(); excelTrMap.put(sheetName, mapTr); System.out.println("Processing sheet: " + sheetName); // Get iterator to all the rows in current sheet Iterator<Row> rowIterator = sheet.iterator(); for (int rownum = 1; rownum <= sheet.getLastRowNum(); rownum++) { Row row = sheet.getRow(rownum); // Get iterator to all cells of current row TR tr = new TRNonDB(); tr.setDate(row.getCell(0).getDateCellValue()); tr.setDescription(row.getCell(1).getStringCellValue()); tr.setDebit((float) row.getCell(2).getNumericCellValue()); tr.setComment(row.getCell(3).getStringCellValue()); tr.setTrType(row.getCell(4).getStringCellValue()); tr.setTaxCategory(row.getCell(5).getStringCellValue()); tr.setProperty(row.getCell(6).getStringCellValue()); tr.setOtherEntity(row.getCell(7).getStringCellValue()); String lockedStr = row.getCell(7).getStringCellValue(); if ("YES".equalsIgnoreCase(lockedStr) || "TRUE".equalsIgnoreCase(lockedStr)) { tr.setLocked(true);//from w w w . j av a 2 s . c o m } tr.setTrId(); mapTr.put(tr.getTrId(), tr); } } return excelTrMap; }
From source file:aco.Utilities.java
License:Open Source License
static void writeInputDataPoints() { //the file already exists if (new File(filePath3).canRead()) { //System.out.println("File already exists.."); try {/*from w w w .j av a 2 s .co m*/ FileInputStream file = new FileInputStream(new File(filePath3)); //Create Workbook instance holding reference to .xlsx file XSSFWorkbook workbook1 = new XSSFWorkbook(file); //Get first/desired sheet from the workbook XSSFSheet sheet1 = workbook1.getSheetAt(11); //define a cell style for bold font CellStyle style = workbook1.createCellStyle(); Font font = workbook1.createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); style.setFont(font); Row r1 = sheet1.getRow(0); if (r1 == null) { // First cell in the row, create r1 = sheet1.createRow(0); } Cell c = r1.getCell(0); if (c == null) { c = r1.createCell(0); } c.setCellValue("VRPTW instance - " + VRPTW.instance.name + "; data point coordinates corresponding to customers' requests"); c.setCellStyle(style); Row r = sheet1.getRow(2); if (r == null) { // First cell in the row, create r = sheet1.createRow(2); } Cell c1 = r.getCell(0); if (c1 == null) { c1 = r.createCell(0); } c1.setCellValue("Point #"); c1.setCellStyle(style); c1 = r.getCell(1); if (c1 == null) { c1 = r.createCell(1); } c1.setCellValue("X Coord"); c1.setCellStyle(style); c1 = r.getCell(2); if (c1 == null) { c1 = r.createCell(2); } c1.setCellValue("Y Coord"); c1.setCellStyle(style); int size = VRPTW.instance.nodes.length; int rowIndex = 3; double x, y; for (int i = 0; i < size; i++) { x = VRPTW.instance.nodes[i].x; y = VRPTW.instance.nodes[i].y; r = sheet1.getRow(rowIndex + i); if (r == null) { // First cell in the row, create //System.out.println("Empty row, create new one"); r = sheet1.createRow(rowIndex + i); } c1 = r.getCell(0); if (c1 == null) { // New cell //System.out.println("Empty cell, create new one"); c1 = r.createCell(0); } c1.setCellValue(i); c1 = r.getCell(1); if (c1 == null) { // New cell //System.out.println("Empty cell, create new one"); c1 = r.createCell(1); } c1.setCellValue(x); c1 = r.getCell(2); if (c1 == null) { // New cell //System.out.println("Empty cell, create new one"); c1 = r.createCell(2); } c1.setCellValue(y); } //Write the workbook in file system FileOutputStream out = new FileOutputStream(new File(filePath3)); workbook1.write(out); out.close(); //System.out.println("Written successfully on disk."); } catch (Exception e) { e.printStackTrace(); } } else { System.out.println("File not exists.."); } }
From source file:aco.Utilities.java
License:Open Source License
static void writeExcel(int n, int m, int result) { //the file already exists; we should add a new row as the last one in the Excel file if (new File(filePath).canRead()) { //System.out.println("File already exists.."); try {/*from www.j a va2s. c om*/ FileInputStream file = new FileInputStream(new File(filePath)); //Create Workbook instance holding reference to .xlsx file XSSFWorkbook workbook1 = new XSSFWorkbook(file); //Get first/desired sheet from the workbook XSSFSheet sheet1 = workbook1.getSheetAt(2); int countRows = sheet1.getLastRowNum() + 1; Row newRow = sheet1.createRow(countRows++); int cellnum = 0; Cell cell = newRow.createCell(cellnum++); cell.setCellValue(n); cell = newRow.createCell(cellnum++); cell.setCellValue(m); cell = newRow.createCell(cellnum++); cell.setCellValue(result); //Write the workbook in file system FileOutputStream out = new FileOutputStream(new File(filePath)); workbook1.write(out); out.close(); //System.out.println("Written successfully on disk."); } catch (Exception e) { e.printStackTrace(); } } else { //Blank workbook XSSFWorkbook workbook2 = new XSSFWorkbook(); //Create a blank sheet XSSFSheet sheet2 = workbook2.createSheet("Results - 51 cities"); //Iterate over data and write to sheet int rownum = 0, cellnum = 0; Row row = sheet2.createRow(rownum++); Cell cell = row.createCell(cellnum++); cell.setCellValue(n); cell = row.createCell(cellnum++); cell.setCellValue(m); cell = row.createCell(cellnum++); cell.setCellValue(result); try { //Write the workbook in file system FileOutputStream out = new FileOutputStream(new File(filePath)); workbook2.write(out); out.close(); //System.out.println("Written successfully on disk."); } catch (Exception e) { e.printStackTrace(); } } }
From source file:aco.Utilities.java
License:Open Source License
static void writeResultsExcel(int trialNumber, boolean saveIterCosts) { Row r, r1;//from w ww . ja v a 2s .c om Cell c; int index1 = 0, index2 = 0, index3 = 0, index4 = 0, index5 = 0; //int index6 = 0; //the file already exists; we should add a new row as the last one in the Excel file if (new File(filePath).canRead()) { //System.out.println("File already exists.."); try { FileInputStream file = new FileInputStream(new File(filePath)); //Create Workbook instance holding reference to .xlsx file XSSFWorkbook workbook1 = new XSSFWorkbook(file); int startIndex = 0, rowIndex = 0; /*switch (VRPTW.m) { case 2: startIndex = 0; rowIndex = 4; break; case 3: startIndex = 2; rowIndex = 5; break; case 5: startIndex = 4; rowIndex = 7; break; case 7: startIndex = 6; rowIndex = 9; break; default: System.out.println("Unknown value for m"); break; }*/ //Get desired sheet from the workbook XSSFSheet sheet1 = workbook1.getSheetAt(startIndex); //for tours /*XSSFSheet sheet2 = workbook1.getSheetAt(startIndex + 1); //for number of assigned cities XSSFSheet sheet3 = workbook1.getSheetAt(startIndex + 2); //for cost of individual subtours XSSFSheet sheet4 = workbook1.getSheetAt(startIndex + 3); //for total cost of subtours XSSFSheet sheet5 = workbook1.getSheetAt(startIndex + 4); //for verbose output of total cost at each 5 iteration */ XSSFSheet sheet2 = workbook1.getSheetAt(startIndex + 1); //for verbose output of longest cost at each 5 iteration //define a cell style for bold font CellStyle style = workbook1.createCellStyle(); Font font = workbook1.createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); style.setFont(font); //define style with bold font and blue color for font CellStyle styleBoldBlue = workbook1.createCellStyle(); font = workbook1.createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); font.setColor(IndexedColors.BLUE.index); styleBoldBlue.setFont(font); index1 = 133; if (!saveIterCosts) { //write only once the name of the algorithm that was run if (trialNumber == 0) { r = sheet1.getRow(index1); if (r == null) { // First cell in the row, create //System.out.println("Empty row, create new one"); r = sheet1.createRow(index1); } c = r.getCell(0); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(0); } c.setCellValue( "Obtained solutions (values) after running new version (ACS MinMax global, voiajor si oras alesi simultan) with local search"); c.setCellStyle(styleBoldBlue); } //write only once the table header index1 = index1 + 3; r = sheet1.getRow(index1); if (r == null) { // First cell in the row, create //System.out.println("Empty row, create new one"); r = sheet1.createRow(index1); } c = r.getCell(0); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(0); } c.setCellValue("Run #"); c.setCellStyle(style); c = r.getCell(1); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(1); } c.setCellValue("MinMax (cost of longest subtour)"); c.setCellStyle(style); c = r.getCell(2); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(2); } c.setCellValue("Total Cost"); c.setCellStyle(style); c = r.getCell(3); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(3); } c.setCellValue("Amplitude"); c.setCellStyle(style); //write number of run index1 = 137 + trialNumber; r = sheet1.getRow(index1); if (r == null) { // First cell in the row, create //System.out.println("Empty row, create new one"); r = sheet1.createRow(index1); } c = r.getCell(0); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(0); } c.setCellValue(trialNumber + 1); //write MinMax (cost of longest subtour) double longestSubtour = getLongestSubtour(); c = r.getCell(1); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(1); } c.setCellValue(longestSubtour); //write total cost double totalCost = getTotalCost(); c = r.getCell(2); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(2); } c.setCellValue(totalCost); //write amplitude double amplitude = getAmplitude(); c = r.getCell(3); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(3); } c.setCellValue(amplitude); } index5 = 859; if (saveIterCosts) { //write only once the name of the algorithm that was run if (trialNumber == 0) { r = sheet2.getRow(index5); if (r == null) { // First cell in the row, create //System.out.println("Empty row, create new one"); r = sheet2.createRow(index5); } c = r.getCell(0); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(0); } c.setCellValue( "Longest cost of subtour at each 5 iteration after running new version (ACS MinMax global, voiajor si oras alesi simultan) with local search"); c.setCellStyle(styleBoldBlue); int tempIndex = index5 + 3; r = sheet2.getRow(tempIndex); if (r == null) { // First cell in the row, create //System.out.println("Empty row, create new one"); r = sheet2.createRow(tempIndex); } ArrayList<Integer> iterNumber = getIterNumber(); c = r.getCell(0); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(0); } c.setCellValue("Nr Iter"); c.setCellStyle(style); int indexTemp = 0; for (int j = 0; j < iterNumber.size(); j++) { indexTemp = tempIndex + 1 + j; r1 = sheet2.getRow(indexTemp); if (r1 == null) { // First cell in the row, create //System.out.println("Empty row, create new one"); r1 = sheet2.createRow(indexTemp); } c = r1.getCell(0); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r1.createCell(0); } c.setCellValue(iterNumber.get(j)); } } index5 = index5 + 3; r = sheet2.getRow(index5); if (r == null) { // First cell in the row, create //System.out.println("Empty row, create new one"); r = sheet2.createRow(index5); } //for each trial run save at each 5 iteration the best longest cost of a subtour so far ArrayList<Double> iterLongestCost = getIterLongestCost(); int index; //for each run write the table header cell c = r.getCell(trialNumber + 1); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(trialNumber + 1); } c.setCellValue("Run " + (trialNumber + 1)); c.setCellStyle(style); for (int j = 0; j < iterLongestCost.size(); j++) { index = index5 + 1 + j; r1 = sheet2.getRow(index); if (r1 == null) { // First cell in the row, create //System.out.println("Empty row, create new one"); r1 = sheet2.createRow(index); } c = r1.getCell(trialNumber + 1); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r1.createCell(trialNumber + 1); } c.setCellValue(iterLongestCost.get(j)); } } //Write the workbook in file system FileOutputStream out = new FileOutputStream(new File(filePath)); workbook1.write(out); out.close(); int nrOfRun = trialNumber + 1; System.out.println("\nRun #" + nrOfRun + " written successfully on disk.\n"); } catch (Exception e) { e.printStackTrace(); } } else { //Blank workbook System.out.println("File " + filePath + " doesn't exists.."); } }