Example usage for org.apache.poi.xssf.usermodel XSSFSheet getRow

List of usage examples for org.apache.poi.xssf.usermodel XSSFSheet getRow

Introduction

In this page you can find the example usage for org.apache.poi.xssf.usermodel XSSFSheet getRow.

Prototype

@Override
public XSSFRow getRow(int rownum) 

Source Link

Document

Returns the logical row ( 0-based).

Usage

From source file:achmad.rifai.admin.ui.Opener.java

private void suplier() {
    try {/* ww  w. j a v a  2  s .  com*/
        achmad.rifai.erp1.util.Db d = achmad.rifai.erp1.util.Work.loadDB();
        org.apache.poi.xssf.usermodel.XSSFWorkbook w = new org.apache.poi.xssf.usermodel.XSSFWorkbook(f);
        org.apache.poi.xssf.usermodel.XSSFSheet s = w.getSheet("Pemasok");
        List<achmad.rifai.erp1.entity.Suplier> l = new java.util.LinkedList<>();
        int x = 1;
        String st = s.getRow(x).getCell(0).getStringCellValue();
        while (!st.isEmpty()) {
            achmad.rifai.erp1.entity.Suplier su = new achmad.rifai.erp1.entity.Suplier();
            int y = x, c, z = x;
            org.apache.poi.xssf.usermodel.XSSFRow r1 = s.getRow(x), r2 = s.getRow(y), r3 = s.getRow(z);
            List<String> l1 = new java.util.LinkedList<>(), l2 = new java.util.LinkedList<>();
            boolean trus = true;
            while (trus || (null == r2.getCell(0) && !r2.getCell(2).getStringCellValue().isEmpty())) {
                trus = false;
                l1.add(r2.getCell(2).getStringCellValue());
                y++;
                r2 = s.getRow(y);
            }
            su.setAlamat(l1);
            trus = true;
            while (trus || (null == r3.getCell(0) && !r3.getCell(3).getStringCellValue().isEmpty())) {
                trus = false;
                l2.add(r3.getCell(3).getStringCellValue());
                z++;
                r3 = s.getRow(z);
            }
            su.setTelp(l2);
            if (y > z)
                c = y;
            else
                c = z;
            su.setKode(r1.getCell(0).getStringCellValue());
            su.setNama(r1.getCell(1).getStringCellValue());
            su.setDeleted(Boolean.parseBoolean(r1.getCell(4).getStringCellValue()));
            l.add(su);
            x = c + 1;
            st = s.getRow(x).getCell(0).getStringCellValue();
        }
        progSuplier.setValue(50);
        for (int c = 0; c < l.size(); c++) {
            new achmad.rifai.erp1.entity.dao.DAOSuplier(d).insert(l.get(c));
            progSuplier.setValue((((1 + c) * 50) / l.size()) + 50);
        }
        d.close();
    } catch (Exception ex) {
        achmad.rifai.erp1.util.Db.hindar(ex);
    }
    progSuplier.setValue(100);
}

From source file:achmad.rifai.admin.ui.Opener.java

private void income() {
    try {//from  ww w  .j a va2s  .  com
        achmad.rifai.erp1.util.Db d = achmad.rifai.erp1.util.Work.loadDB();
        org.apache.poi.xssf.usermodel.XSSFWorkbook w = new org.apache.poi.xssf.usermodel.XSSFWorkbook(f);
        org.apache.poi.xssf.usermodel.XSSFSheet s = w.getSheet("Pemasukan");
        List<achmad.rifai.erp1.entity.Terima> l = new java.util.LinkedList<>();
        int x = 1;
        String st = s.getRow(x).getCell(0).getStringCellValue();
        while (!st.isEmpty()) {
            achmad.rifai.erp1.entity.Terima t = new achmad.rifai.erp1.entity.Terima();
            org.apache.poi.xssf.usermodel.XSSFRow r = s.getRow(x);
            t.setKode(r.getCell(0).getStringCellValue());
            t.setJurnal(r.getCell(1).getStringCellValue());
            t.setTgl(org.joda.time.DateTime.parse(r.getCell(2).getStringCellValue()));
            t.setUang(org.joda.money.Money.parse(r.getCell(3).getStringCellValue()));
            t.setDeleted(Boolean.parseBoolean(r.getCell(4).getStringCellValue()));
            x++;
            st = s.getRow(x).getCell(0).getStringCellValue();
            l.add(t);
        }
        progIncome.setValue(50);
        for (int c = 0; c < l.size(); c++) {
            new achmad.rifai.erp1.entity.dao.DAOTerima(d).insert(l.get(c));
            progIncome.setValue((((1 + c) * 50) / l.size()) + 50);
        }
        d.close();
    } catch (Exception ex) {
        achmad.rifai.erp1.util.Db.hindar(ex);
    }
    progIncome.setValue(100);
}

From source file:achmad.rifai.admin.ui.Opener.java

private void tracks() {
    try {//  ww w  .  j  ava  2s.  c o  m
        achmad.rifai.erp1.util.Db d = achmad.rifai.erp1.util.Work.loadDB();
        org.apache.poi.xssf.usermodel.XSSFWorkbook w = new org.apache.poi.xssf.usermodel.XSSFWorkbook(f);
        org.apache.poi.xssf.usermodel.XSSFSheet s = w.getSheet("Buku Perilaku");
        List<achmad.rifai.erp1.entity.Tracks> l = new java.util.LinkedList<>();
        int x = 2;
        String st = s.getRow(x).getCell(0).getStringCellValue();
        while (!st.isEmpty()) {
            achmad.rifai.erp1.entity.Tracks t = new achmad.rifai.erp1.entity.Tracks();
            int y = x;
            org.apache.poi.xssf.usermodel.XSSFRow r1 = s.getRow(x), r2 = s.getRow(y);
            List<achmad.rifai.erp1.entity.Jejak> l1 = new java.util.LinkedList<>();
            boolean trus = true;
            while (trus || null == r2.getCell(0)) {
                achmad.rifai.erp1.entity.Jejak j = new achmad.rifai.erp1.entity.Jejak();
                j.setAksi(r2.getCell(2).getStringCellValue());
                j.setWaktu(org.joda.time.DateTime.parse(r2.getCell(3).getStringCellValue()));
                l1.add(j);
                trus = false;
                y++;
                r2 = s.getRow(y);
            }
            t.setL(l1);
            t.setKode(r1.getCell(0).getStringCellValue());
            t.setId(r1.getCell(1).getStringCellValue());
            t.setBln(Month.valueOf(r1.getCell(4).getStringCellValue()));
            t.setTahun(Integer.parseInt(r1.getCell(5).getStringCellValue()));
            t.setDeleted(Boolean.parseBoolean(r1.getCell(6).getStringCellValue()));
            l.add(t);
            x = y + 1;
            st = s.getRow(x).getCell(0).getStringCellValue();
        }
        progTrack.setValue(50);
        for (int c = 0; c < l.size(); c++) {
            new achmad.rifai.erp1.entity.dao.DAOTracks(d).insert(l.get(c));
            progTrack.setValue((((1 + c) * 50) / l.size()) + 50);
        }
        d.close();
    } catch (Exception ex) {
        achmad.rifai.erp1.util.Db.hindar(ex);
    }
    progTrack.setValue(100);
}

From source file:achmad.rifai.admin.ui.Opener.java

private void tugas() {
    try {//from  www  .j ava 2s.c om
        achmad.rifai.erp1.util.Db d = achmad.rifai.erp1.util.Work.loadDB();
        org.apache.poi.xssf.usermodel.XSSFWorkbook w = new org.apache.poi.xssf.usermodel.XSSFWorkbook(f);
        org.apache.poi.xssf.usermodel.XSSFSheet s = w.getSheet("Tugas");
        List<achmad.rifai.erp1.entity.Tugas> l = new java.util.LinkedList<>();
        int x = 2;
        String st = s.getRow(x).getCell(0).getStringCellValue();
        while (!st.isEmpty()) {
            achmad.rifai.erp1.entity.Tugas t = new achmad.rifai.erp1.entity.Tugas();
            int y = x;
            org.apache.poi.xssf.usermodel.XSSFRow r1 = s.getRow(x), r2 = s.getRow(y);
            List<achmad.rifai.erp1.entity.Petugas> l1 = new java.util.LinkedList<>();
            boolean trus = true;
            while (trus || null == r2.getCell(0)) {
                achmad.rifai.erp1.entity.Petugas p = new achmad.rifai.erp1.entity.Petugas();
                p.setKaryawan(r2.getCell(3).getStringCellValue());
                p.setDiambil(Boolean.parseBoolean(r2.getCell(4).getStringCellValue()));
                p.setSedang(Boolean.parseBoolean(r2.getCell(5).getStringCellValue()));
                p.setTerlaksana(Boolean.parseBoolean(r2.getCell(6).getStringCellValue()));
                l1.add(p);
                y++;
                r2 = s.getRow(y);
                trus = false;
            }
            t.setL(l1);
            t.setKode(r1.getCell(0).getStringCellValue());
            t.setNo(Integer.parseInt(r1.getCell(1).getStringCellValue()));
            t.setTgl(java.sql.Date.valueOf(r1.getCell(2).getStringCellValue()));
            t.setKet(r1.getCell(7).getStringCellValue());
            t.setBatal(Boolean.parseBoolean(r1.getCell(8).getStringCellValue()));
            t.setPending(Boolean.parseBoolean(r1.getCell(9).getStringCellValue()));
            t.setDeleted(Boolean.parseBoolean(r1.getCell(10).getStringCellValue()));
            x = y + 1;
            l.add(t);
            st = s.getRow(x).getCell(0).getStringCellValue();
        }
        progTugas.setValue(50);
        for (int c = 0; c < l.size(); c++) {
            new achmad.rifai.erp1.entity.dao.DAOTugas(d).insert(l.get(c));
            progTugas.setValue((((1 + c) * 50) / l.size()) + 50);
        }
        d.close();
    } catch (Exception ex) {
        achmad.rifai.erp1.util.Db.hindar(ex);
    }
    progTugas.setValue(100);
}

From source file:achmad.rifai.admin.ui.Opener.java

private void bonus() {
    try {//  w  w w  .ja  v a2s  . c o  m
        achmad.rifai.erp1.util.Db d = achmad.rifai.erp1.util.Work.loadDB();
        org.apache.poi.xssf.usermodel.XSSFWorkbook w = new org.apache.poi.xssf.usermodel.XSSFWorkbook(f);
        org.apache.poi.xssf.usermodel.XSSFSheet s = w.getSheet("bonus");
        List<achmad.rifai.erp1.entity.BulanBonus> l = new java.util.LinkedList<>();
        int x = 2;
        String st = s.getRow(x).getCell(0).getStringCellValue();
        while (!st.isEmpty()) {
            achmad.rifai.erp1.entity.BulanBonus b = new achmad.rifai.erp1.entity.BulanBonus();
            int y = x;
            org.apache.poi.xssf.usermodel.XSSFRow r1 = s.getRow(x), r2 = s.getRow(y);
            List<achmad.rifai.erp1.entity.Bonusan> l1 = new java.util.LinkedList<>();
            boolean trus = true;
            while (trus || null == r2.getCell(0)) {
                achmad.rifai.erp1.entity.Bonusan bo = new achmad.rifai.erp1.entity.Bonusan();
                bo.setNomer(Integer.parseInt(r2.getCell(2).getStringCellValue()));
                bo.setJumlah(org.joda.money.Money.parse(r2.getCell(3).getStringCellValue()));
                l1.add(bo);
                y++;
                r2 = s.getRow(y);
                trus = false;
            }
            b.setL(l1);
            b.setKode(r1.getCell(0).getStringCellValue());
            b.setPeg(r1.getCell(1).getStringCellValue());
            b.setBln(Month.valueOf(r1.getCell(4).getStringCellValue()));
            b.setThn(java.time.Year.parse(r1.getCell(5).getStringCellValue()));
            b.setDeleted(Boolean.parseBoolean(r1.getCell(6).getStringCellValue()));
            l.add(b);
            x = y + 1;
            st = s.getRow(x).getCell(0).getStringCellValue();
        }
        progBonus.setValue(50);
        for (int c = 0; c < l.size(); c++) {
            new achmad.rifai.erp1.entity.dao.DAOBulanBonus(d).insert(l.get(c));
            progBonus.setValue((((1 + c) * 50) / l.size()) + 50);
        }
        d.close();
    } catch (Exception ex) {
        achmad.rifai.erp1.util.Db.hindar(ex);
    }
    progBonus.setValue(100);
}

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  ww.ja  va  2s. c o  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 writeResultsExcel(int trialNumber, boolean saveIterCosts) {
    Row r, r1;//from   w  w  w . java 2s  .  c  o m
    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..");

    }
}

From source file:aco.Utilities.java

License:Open Source License

static void writeParetoSet(ArrayList<Ant> bestSoFarPareto, int trial) {
    Row r;//from   w ww  . j  a  v a  2 s. c  o  m
    Cell c;
    int lineNumber = 0;

    //filePath1 += InOut.max_iterations + " iter (ACO MinMax_vers noua).xlsx";
    //System.out.println("file path=" + filePath1);

    //the file already exists; we should add a new row as the last one in the Excel file
    if (new File(filePath1).canRead()) {
        //System.out.println("File already exists..");
        try {
            FileInputStream file = new FileInputStream(new File(filePath1));

            //Create Workbook instance holding reference to .xlsx file
            XSSFWorkbook workbook1 = new XSSFWorkbook(file);

            //Get first/desired sheet from the workbook
            XSSFSheet sheet1 = workbook1.getSheetAt(trial);

            //write table header cells
            r = sheet1.getRow(lineNumber);
            if (r == null) {
                // First cell in the row, create
                r = sheet1.createRow(lineNumber);
            }
            c = r.getCell(0);
            if (c == null) {
                // New cell
                c = r.createCell(0);
            }
            c.setCellValue("Point #");
            c = r.getCell(1);
            if (c == null) {
                // New cell
                c = r.createCell(1);
            }
            c.setCellValue("Total tours length");
            c = r.getCell(2);
            if (c == null) {
                // New cell
                c = r.createCell(2);
            }
            c.setCellValue("Amplitude of tours");
            c = r.getCell(3);
            if (c == null) {
                // New cell
                c = r.createCell(3);
            }
            c.setCellValue("List with cost of subtours");

            lineNumber++;
            for (int i = 0; i < bestSoFarPareto.size(); i++) {
                r = sheet1.getRow(i + lineNumber);
                if (r == null) {
                    // First cell in the row, create
                    r = sheet1.createRow(i + lineNumber);
                }
                //write point id
                c = r.getCell(0);
                if (c == null) {
                    // New cell
                    c = r.createCell(0, Cell.CELL_TYPE_NUMERIC);
                }
                c.setCellValue(i + 1);
                //write total cost and amplitude
                for (int indexObj = 0; indexObj < 2; indexObj++) {
                    c = r.getCell(indexObj + 1);
                    if (c == null) {
                        // New cell
                        c = r.createCell(indexObj + 1, Cell.CELL_TYPE_NUMERIC);
                    }
                    c.setCellValue(bestSoFarPareto.get(i).costObjectives[indexObj]);
                }
                //write cost of each individual subtour
                for (int j = 0; j < bestSoFarPareto.get(i).tour_lengths.size(); j++) {
                    c = r.getCell(j + 3);
                    if (c == null) {
                        // New cell
                        c = r.createCell(j + 3);
                    }
                    c.setCellValue(bestSoFarPareto.get(i).tour_lengths.get(j));
                }
            }

            //Write the workbook in file system
            FileOutputStream out = new FileOutputStream(new File(filePath1));
            workbook1.write(out);
            out.close();

            //System.out.println("\nWritten Pareto front points successfully on disk.\n");
            int nrOfRun = trial + 1;
            System.out.println("\nRun #" + nrOfRun + " written Pareto front points successfully on disk.\n");
        } catch (Exception e) {
            e.printStackTrace();
        }

    } else {
        System.out.println(" File " + filePath1 + " doesn't exists");
    }

}

From source file:aco.Utilities.java

License:Open Source License

static void writeExcelFinalSolution(int trial, double scalledValue) {
    Row r;//  w  w  w  . j  av  a  2  s.  co  m
    Cell c;
    int index1 = 0;

    //the file already exists; we should add a new row as the last one in the Excel file
    if (new File(filePath5).canRead()) {
        //System.out.println("File already exists..");
        try {
            FileInputStream file = new FileInputStream(new File(filePath5));

            //Create Workbook instance holding reference to .xlsx file
            XSSFWorkbook workbook1 = new XSSFWorkbook(file);

            //Get desired sheet from the workbook
            XSSFSheet sheet1 = workbook1.getSheetAt(0);

            //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 = 8; //8  //26

            index1 = index1 + trial;
            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);
            }

            int nrOfRun = trial + 1;
            //write trial number (Run #)
            c = r.getCell(15);
            if (c == null) {
                // New cell
                //System.out.println("Empty cell, create new one");
                c = r.createCell(15);
            }
            c.setCellValue(nrOfRun);

            //write number of used vehicles
            c = r.getCell(16);
            if (c == null) {
                // New cell
                //System.out.println("Empty cell, create new one");
                c = r.createCell(16);
            }
            c.setCellValue(Ants.best_so_far_ant.usedVehicles);

            //write total traveled distance
            c = r.getCell(17);
            if (c == null) {
                // New cell
                //System.out.println("Empty cell, create new one");
                c = r.createCell(17);
            }
            c.setCellValue(scalledValue);

            //write the total number of feasible solutions
            c = r.getCell(18);
            if (c == null) {
                // New cell
                //System.out.println("Empty cell, create new one");
                c = r.createCell(18);
            }
            c.setCellValue(InOut.noSolutions);

            //Write the workbook in file system
            FileOutputStream out = new FileOutputStream(new File(filePath5));
            workbook1.write(out);
            out.close();

            System.out.println("\nRun #" + nrOfRun + " written successfully on disk.\n");
        }

        catch (Exception e) {
            e.printStackTrace();
        }

    } else {
        //Blank workbook
        System.out.println("File " + filePath5 + " doesn't exists..");

    }
}

From source file:ADP_Streamline.MatrixReader.java

public String CellIteration(XSSFSheet sheet, String columnletter, int rownum, int columncount, int rowcount)
        throws Exception {

    if (columncount > 0) {
        int column = (int) columnletter.charAt(0) + columncount;
        columnletter = Character.toString((char) column);
    }/*from ww  w .  j ava2 s.  co m*/

    CellReference cr = new CellReference(columnletter + (rownum + rowcount));
    Row row = sheet.getRow(cr.getRow());
    String Roles = row.getCell(cr.getCol()).getStringCellValue();

    return Roles;
}