Example usage for org.apache.poi.xssf.usermodel XSSFRow createCell

List of usage examples for org.apache.poi.xssf.usermodel XSSFRow createCell

Introduction

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

Prototype

@Override
public XSSFCell createCell(int columnIndex) 

Source Link

Document

Use this to create new cells within the row and return it.

Usage

From source file:emhs.db.model.GBEntryBook.java

public int addGuest(String name, String licencePlateNo, String reason, String timeIn) {
    XSSFRow row = guestSheet.createRow(guestRowIdx);
    row.createCell(0).setCellValue(name);
    row.createCell(1).setCellValue(licencePlateNo);
    row.createCell(2).setCellValue(reason);
    row.createCell(3).setCellValue(timeIn);

    return guestRowIdx++;
}

From source file:emhs.db.model.GBEntryBook.java

public int addStaff(String name, String reason, String timeIn) {
    XSSFRow row = staffSheet.createRow(staffRowIdx);
    row.createCell(0).setCellValue(name);
    row.createCell(1).setCellValue(reason);
    row.createCell(2).setCellValue(timeIn);

    return staffRowIdx++;
}

From source file:emhs.db.model.GBEntryBook.java

public int addSubstitute(String name, String absentTeacher, String time, String phoneNumber, String jobNumber,
        String licencePlateNo, String timeIn) {
    XSSFRow row = substituteSheet.createRow(substituteRowIdx);
    row.createCell(0).setCellValue(name);
    row.createCell(1).setCellValue(absentTeacher);
    row.createCell(2).setCellValue(time);
    row.createCell(3).setCellValue(phoneNumber);
    row.createCell(4).setCellValue(jobNumber);
    row.createCell(5).setCellValue(licencePlateNo);
    row.createCell(6).setCellValue(timeIn);

    return substituteRowIdx++;
}

From source file:es.SSII2.manager.ExcelManagerAccount.java

public void actualizarCuentas(ArrayList<String> cuentas, ArrayList<String> cuentasCorrectas,
        ArrayList<String> arrayIban, ArrayList<String> pos) throws IOException, ParseException {

    int row, col;
    String originalCuenta, nuevaCuenta, iban, posicion, entidad, oficina, dc, numCuenta;
    String[] a;/* w  w  w . j av  a  2  s .  c  o  m*/

    FileInputStream file;
    file = new FileInputStream(new File(excel));

    FileOutputStream outFile;

    XSSFWorkbook workbook = new XSSFWorkbook(file);
    XSSFSheet sheet = workbook.getSheetAt(0);
    XSSFRow rowIban;
    XSSFCell cellIban;
    Cell cellCuenta;

    //sacar las cuentas
    for (int i = 0; i < cuentas.size(); i++) {

        originalCuenta = cuentas.get(i);//se coje la cuenta original
        nuevaCuenta = cuentasCorrectas.get(i);//se coje la cuenta actualizada   
        iban = arrayIban.get(i);// cojer el iban

        posicion = pos.get(i);//se coje la posicion
        a = posicion.split("-");//split del string "1-3" de las posiciones que estan el el arraylist
        row = Integer.parseInt(a[0]);//fila "1"
        col = Integer.parseInt(a[1]);//columna "3"

        //insertar el iban
        rowIban = sheet.getRow(row);//coje la fila
        cellIban = rowIban.createCell(1 + col);//crea la celda
        cellIban.setCellValue(iban);

        //2096 0056 16 3231500000
        entidad = nuevaCuenta.substring(0, 4);
        oficina = nuevaCuenta.substring(4, 8);
        dc = nuevaCuenta.substring(8, 10);
        numCuenta = nuevaCuenta.substring(10);

        //actualizar la cuenta si esta mal el cc
        if (!originalCuenta.equals(nuevaCuenta)) {

            cellCuenta = sheet.getRow(row).getCell(col); //obtiene la fila y columna
            DecimalFormat df = new DecimalFormat("#");
            Number cuenta = df.parse(nuevaCuenta);
            cellCuenta.setCellValue(cuenta.doubleValue());

            System.out.println(
                    "Cuenta actualizada: " + iban + "-" + entidad + "-" + oficina + "-" + dc + "-" + numCuenta);

        } else {

            System.out.println(
                    "Cuenta correcta:    " + iban + "-" + entidad + "-" + oficina + "-" + dc + "-" + numCuenta);

        }

    } //for

    outFile = new FileOutputStream(new File(excel));
    //escribe en el excel
    workbook.write(outFile);
    outFile.close();

    file.close();//cierra el archivo  

}

From source file:es.SSII2.manager.ExcelManagerMail.java

public void actualizarDnis() throws IOException {

    int row;/*from  www  .  j av  a2s.  co  m*/
    int col = 15;

    FileInputStream file;
    file = new FileInputStream(new File(excel));

    XSSFWorkbook workbook = new XSSFWorkbook(file);
    XSSFSheet sheet = workbook.getSheetAt(0);

    for (int i = 0; i < arrayWorkers.size(); i++) {

        row = i;
        XSSFRow rowEmail = sheet.getRow(row + 1); //coje la fila
        XSSFCell cellEmail = rowEmail.createCell(col); //crea la celda
        cellEmail.setCellValue(arrayWorkers.get(i).getEmail());

        //escribe en el excel
        try (FileOutputStream outFile = new FileOutputStream(new File(excel))) {
            workbook.write(outFile);

        }

    } //for
}

From source file:es.upm.oeg.tools.rdfshapes.libdemo.ApachePoiDemo.java

License:Apache License

public static void main(String[] args) throws Exception {

    String filename = "test.xls";

    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sheet = wb.createSheet("Cardinality");

    //iterating r number of rows
    for (int r = 0; r < 5; r++) {
        XSSFRow row = sheet.createRow(r);

        //iterating c number of columns
        for (int c = 0; c < 5; c++) {
            XSSFCell cell = row.createCell(c);

            cell.setCellValue("Cell " + r + " " + c);
        }// w ww.java  2  s  .c  o  m
    }

    FileOutputStream fileOut = new FileOutputStream(filename);
    wb.write(fileOut);
    fileOut.close();

}

From source file:es.upm.oeg.tools.rdfshapes.patterns.DatatypeObjectPropertyPatterns.java

License:Apache License

public static void main(String[] args) throws Exception {

    String endpoint = "http://3cixty.eurecom.fr/sparql";

    List<String> classList = Files.readAllLines(Paths.get(classListPath), Charset.defaultCharset());

    String classPropertyQueryString = readFile(classPropertyQueryPath, Charset.defaultCharset());
    String propertyCardinalityQueryString = readFile(propertyCardinalityQueryPath, Charset.defaultCharset());
    String individualCountQueryString = readFile(individualCountQueryPath, Charset.defaultCharset());
    String objectCountQueryString = readFile(objectCountQueryPath, Charset.defaultCharset());
    String tripleCountQueryString = readFile(tripleCountQueryPath, Charset.defaultCharset());
    String literalCountQueryString = readFile(literalCountQueryPath, Charset.defaultCharset());
    String blankCountQueryString = readFile(blankCountQueryPath, Charset.defaultCharset());
    String iriCountQueryString = readFile(iriCountQueryPath, Charset.defaultCharset());
    String datatypeCountQueryString = readFile(datatypeCountsPath, Charset.defaultCharset());

    DecimalFormat df = new DecimalFormat("0.0000");

    //Create the Excel workbook and sheet
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sheet = wb.createSheet("Cardinality");

    int currentExcelRow = 0;
    int classStartRow = 0;

    for (String clazz : classList) {

        System.out.println("Class: " + clazz);

        Map<String, String> litMap = new HashMap<>();
        Map<String, String> iriMap = ImmutableMap.of("class", clazz);

        String queryString = bindQueryString(individualCountQueryString,
                ImmutableMap.of(IRI_BINDINGS, iriMap, LITERAL_BINDINGS, litMap));

        int individualCount;
        List<RDFNode> c = executeQueryForList(queryString, endpoint, "c");
        if (c.size() == 1) {
            individualCount = c.get(0).asLiteral().getInt();
        } else {/* w w w . j  a  v  a2  s.c om*/
            continue;
        }

        // If there are zero individuals, continue
        if (individualCount == 0) {
            throw new IllegalStateException("Check whether " + classListPath + " and " + endpoint + " match.");
        }

        classStartRow = currentExcelRow;
        XSSFRow row = sheet.createRow(currentExcelRow);
        XSSFCell cell = row.createCell(0);
        cell.setCellValue(clazz);

        litMap = new HashMap<>();
        iriMap = ImmutableMap.of("class", clazz);
        queryString = bindQueryString(classPropertyQueryString,
                ImmutableMap.of(IRI_BINDINGS, iriMap, LITERAL_BINDINGS, litMap));
        List<RDFNode> nodeList = executeQueryForList(queryString, endpoint, "p");

        //            System.out.println("***");
        //            System.out.println("### **" + clazz + "**");
        //            System.out.println("***");
        //            System.out.println();

        cell.getCellStyle().setAlignment(CellStyle.ALIGN_CENTER);

        for (RDFNode property : nodeList) {
            if (property.isURIResource()) {

                System.out.println("          " + property);

                int tripleCount;
                int objectCount;
                int literalCount;
                int blankCount;
                int iriCount;

                String propertyURI = property.asResource().getURI();

                XSSFRow propertyRow = sheet.getRow(currentExcelRow);
                if (propertyRow == null) {
                    propertyRow = sheet.createRow(currentExcelRow);
                }
                currentExcelRow++;
                XSSFCell propertyCell = propertyRow.createCell(1);
                propertyCell.setCellValue(propertyURI);

                litMap = new HashMap<>();
                iriMap = ImmutableMap.of("class", clazz, "p", propertyURI);

                queryString = bindQueryString(tripleCountQueryString,
                        ImmutableMap.of(IRI_BINDINGS, iriMap, LITERAL_BINDINGS, litMap));

                c = executeQueryForList(queryString, endpoint, "c");
                if (c.size() > 0) {
                    tripleCount = c.get(0).asLiteral().getInt();
                } else {
                    tripleCount = 0;
                }

                queryString = bindQueryString(objectCountQueryString,
                        ImmutableMap.of(IRI_BINDINGS, iriMap, LITERAL_BINDINGS, litMap));

                c = executeQueryForList(queryString, endpoint, "c");
                if (c.size() > 0) {
                    objectCount = c.get(0).asLiteral().getInt();
                } else {
                    objectCount = 0;
                }

                queryString = bindQueryString(literalCountQueryString,
                        ImmutableMap.of(IRI_BINDINGS, iriMap, LITERAL_BINDINGS, litMap));
                c = executeQueryForList(queryString, endpoint, "c");
                if (c.size() > 0) {
                    literalCount = c.get(0).asLiteral().getInt();
                } else {
                    literalCount = 0;
                }

                queryString = bindQueryString(blankCountQueryString,
                        ImmutableMap.of(IRI_BINDINGS, iriMap, LITERAL_BINDINGS, litMap));
                c = executeQueryForList(queryString, endpoint, "c");
                if (c.size() > 0) {
                    blankCount = c.get(0).asLiteral().getInt();
                } else {
                    blankCount = 0;
                }

                queryString = bindQueryString(iriCountQueryString,
                        ImmutableMap.of(IRI_BINDINGS, iriMap, LITERAL_BINDINGS, litMap));
                c = executeQueryForList(queryString, endpoint, "c");
                if (c.size() > 0) {
                    iriCount = c.get(0).asLiteral().getInt();
                } else {
                    iriCount = 0;
                }

                XSSFCell objectCountCell = propertyRow.createCell(2);
                objectCountCell.setCellValue(objectCount);

                XSSFCell uniqueObjectsCell = propertyRow.createCell(3);
                uniqueObjectsCell.setCellValue(df.format(((double) objectCount) / tripleCount));

                XSSFCell literalCell = propertyRow.createCell(4);
                literalCell.setCellValue(df.format((((double) literalCount) / objectCount)));

                XSSFCell iriCell = propertyRow.createCell(5);
                iriCell.setCellValue(df.format((((double) iriCount) / objectCount)));

                XSSFCell blankCell = propertyRow.createCell(6);
                blankCell.setCellValue(df.format((((double) blankCount) / objectCount)));

                if (literalCount > 0) {

                    litMap = new HashMap<>();
                    iriMap = ImmutableMap.of("class", clazz, "p", propertyURI);

                    queryString = bindQueryString(datatypeCountQueryString,
                            ImmutableMap.of(IRI_BINDINGS, iriMap, LITERAL_BINDINGS, litMap));
                    List<Map<String, RDFNode>> solnMaps = executeQueryForList(queryString, endpoint,
                            ImmutableSet.of("datatype", "c"));

                    int i = 1;
                    for (Map<String, RDFNode> soln : solnMaps) {
                        String datatype = soln.get("datatype").asResource().getURI();
                        int count = soln.get("c").asLiteral().getInt();

                        XSSFCell dataCell = propertyRow.createCell(6 + i++);
                        dataCell.setCellValue(datatype);

                        dataCell = propertyRow.createCell(6 + i++);
                        dataCell.setCellValue(df.format((((double) count) / objectCount)));

                    }

                }

                //                    System.out.println("* " + propertyURI);
                //                    System.out.println();
                //
                //                    System.out.println("| Object Count | Unique Objects | Literals | IRIs | Blank Nodes | ");
                //                    System.out.println("|---|---|---|---|---|");
                //                    System.out.println(String.format("|%d|%d (%.2f%%) |%d (%.2f%%)|%d (%.2f%%)|%d (%.2f%%)|",
                //                            tripleCount,
                //                            objectCount, ((((double) objectCount)/tripleCount)*100),
                //                            literalCount, ((((double) literalCount)/objectCount)*100),
                //                            iriCount, ((((double) iriCount)/objectCount)*100),
                //                            blankCount, ((((double) blankCount)/objectCount)*100)));
                //                    System.out.println();
            }
        }
    }

    String filename = "literals.xls";
    FileOutputStream fileOut = new FileOutputStream(filename);
    wb.write(fileOut);
    fileOut.close();

}

From source file:es.upm.oeg.tools.rdfshapes.utils.CadinalityResultGenerator.java

License:Apache License

public static void main(String[] args) throws Exception {

    String endpoint = "http://3cixty.eurecom.fr/sparql";

    List<String> classList = Files.readAllLines(Paths.get(classListPath), Charset.defaultCharset());

    String classPropertyQueryString = readFile(classPropertyQueryPath, Charset.defaultCharset());
    String propertyCardinalityQueryString = readFile(propertyCardinalityQueryPath, Charset.defaultCharset());
    String individualCountQueryString = readFile(individualCountQueryPath, Charset.defaultCharset());

    DecimalFormat df = new DecimalFormat("0.0000");

    //Create the Excel workbook and sheet
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sheet = wb.createSheet("Cardinality");

    int currentExcelRow = 0;
    int classStartRow = 0;

    for (String clazz : classList) {

        Map<String, String> litMap = new HashMap<>();
        Map<String, String> iriMap = ImmutableMap.of("class", clazz);

        String queryString = bindQueryString(individualCountQueryString,
                ImmutableMap.of(IRI_BINDINGS, iriMap, LITERAL_BINDINGS, litMap));

        int individualCount;
        List<RDFNode> c = executeQueryForList(queryString, endpoint, "c");
        if (c.size() == 1) {
            individualCount = c.get(0).asLiteral().getInt();
        } else {/*  w w  w.  ja v  a2 s .  c  om*/
            continue;
        }

        // If there are zero individuals, continue
        if (individualCount == 0) {
            throw new IllegalStateException("Check whether " + classListPath + " and " + endpoint + " match.");
        }

        //            System.out.println("***");
        //            System.out.println("### **" + clazz + "** (" + individualCount + ")");
        //            System.out.println("***");
        //            System.out.println();

        classStartRow = currentExcelRow;
        XSSFRow row = sheet.createRow(currentExcelRow);
        XSSFCell cell = row.createCell(0);
        cell.setCellValue(clazz);
        cell.getCellStyle().setAlignment(CellStyle.ALIGN_CENTER);

        queryString = bindQueryString(classPropertyQueryString,
                ImmutableMap.of(IRI_BINDINGS, iriMap, LITERAL_BINDINGS, litMap));

        List<RDFNode> nodeList = executeQueryForList(queryString, endpoint, "p");

        for (RDFNode property : nodeList) {
            if (property.isURIResource()) {

                DescriptiveStatistics stats = new DescriptiveStatistics();

                String propertyURI = property.asResource().getURI();
                //                    System.out.println("* " + propertyURI);
                //                    System.out.println();

                XSSFRow propertyRow = sheet.getRow(currentExcelRow);
                if (propertyRow == null) {
                    propertyRow = sheet.createRow(currentExcelRow);
                }
                currentExcelRow++;

                XSSFCell propertyCell = propertyRow.createCell(1);
                propertyCell.setCellValue(propertyURI);

                Map<String, String> litMap2 = new HashMap<>();
                Map<String, String> iriMap2 = ImmutableMap.of("class", clazz, "p", propertyURI);

                queryString = bindQueryString(propertyCardinalityQueryString,
                        ImmutableMap.of(IRI_BINDINGS, iriMap2, LITERAL_BINDINGS, litMap2));

                List<Map<String, RDFNode>> solnMaps = executeQueryForList(queryString, endpoint,
                        ImmutableSet.of("card", "count"));

                int sum = 0;
                List<CardinalityCount> cardinalityList = new ArrayList<>();
                if (solnMaps.size() > 0) {

                    for (Map<String, RDFNode> soln : solnMaps) {
                        int count = soln.get("count").asLiteral().getInt();
                        int card = soln.get("card").asLiteral().getInt();

                        for (int i = 0; i < count; i++) {
                            stats.addValue(card);
                        }

                        CardinalityCount cardinalityCount = new CardinalityCount(card, count,
                                (((double) count) / individualCount) * 100);
                        cardinalityList.add(cardinalityCount);
                        sum += count;
                    }

                    // Check for zero cardinality instances
                    int count = individualCount - sum;
                    if (count > 0) {
                        for (int i = 0; i < count; i++) {
                            stats.addValue(0);
                        }
                        CardinalityCount cardinalityCount = new CardinalityCount(0, count,
                                (((double) count) / individualCount) * 100);
                        cardinalityList.add(cardinalityCount);
                    }
                }

                Map<Integer, Double> cardMap = new HashMap<>();
                for (CardinalityCount count : cardinalityList) {
                    cardMap.put(count.getCardinality(), count.getPrecentage());
                }

                XSSFCell instanceCountCell = propertyRow.createCell(2);
                instanceCountCell.setCellValue(individualCount);

                XSSFCell minCell = propertyRow.createCell(3);
                minCell.setCellValue(stats.getMin());

                XSSFCell maxCell = propertyRow.createCell(4);
                maxCell.setCellValue(stats.getMax());

                XSSFCell p1 = propertyRow.createCell(5);
                p1.setCellValue(stats.getPercentile(1));

                XSSFCell p99 = propertyRow.createCell(6);
                p99.setCellValue(stats.getPercentile(99));

                XSSFCell mean = propertyRow.createCell(7);
                mean.setCellValue(df.format(stats.getMean()));

                for (int i = 0; i < 21; i++) {
                    XSSFCell dataCell = propertyRow.createCell(8 + i);
                    Double percentage = cardMap.get(i);
                    if (percentage != null) {
                        dataCell.setCellValue(df.format(percentage));
                    } else {
                        dataCell.setCellValue(0);
                    }
                }

                //                    System.out.println("| Min Card. |Max Card. |");
                //                    System.out.println("|---|---|");
                //                    System.out.println("| ? | ? |");
                //                    System.out.println();

            }
        }

        //System.out.println("class start: " + classStartRow + ", class end: " + (currentExcelRow -1));
        //We have finished writting properties of one class, now it's time to merge the cells
        int classEndRow = currentExcelRow - 1;
        if (classStartRow < classEndRow) {
            sheet.addMergedRegion(new CellRangeAddress(classStartRow, classEndRow, 0, 0));
        }

    }

    String filename = "3cixty.xls";
    FileOutputStream fileOut = new FileOutputStream(filename);
    wb.write(fileOut);
    fileOut.close();
}

From source file:es.upm.oeg.tools.rdfshapes.utils.CardinalityTemplateGenerator.java

License:Apache License

public static void main(String[] args) throws Exception {

    OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_RULE_INF,
            ModelFactory.createDefaultModel());
    model.read("http://dublincore.org/2012/06/14/dcelements.ttl");

    String endpoint = "http://infra2.dia.fi.upm.es:8899/sparql";

    List<String> classList = Files.readAllLines(Paths.get(classListPath), Charset.defaultCharset());

    String classPropertyQueryString = readFile(classPropertyQueryPath, Charset.defaultCharset());
    String propertyCardinalityQueryString = readFile(propertyCardinalityQueryPath, Charset.defaultCharset());
    String individualCountQueryString = readFile(individualCountQueryPath, Charset.defaultCharset());

    //Create the Excel workbook and sheet
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sheet = wb.createSheet("Cardinality");

    int currentExcelRow = 0;
    int classStartRow = 0;

    for (String clazz : classList) {

        Map<String, String> litMap = new HashMap<>();
        Map<String, String> iriMap = ImmutableMap.of("class", clazz);

        String queryString = bindQueryString(individualCountQueryString,
                ImmutableMap.of(IRI_BINDINGS, iriMap, LITERAL_BINDINGS, litMap));

        int individualCount;
        List<RDFNode> c = executeQueryForList(queryString, endpoint, "c");
        if (c.size() == 1) {
            individualCount = c.get(0).asLiteral().getInt();
        } else {//from  w ww. j a  va 2  s  .co m
            continue;
        }

        // If there are zero individuals, continue
        if (individualCount == 0) {
            throw new IllegalStateException("Check whether " + classListPath + " and " + endpoint + " match.");
        }

        //            System.out.println("***");
        //            System.out.println("### **" + clazz + "** (" + individualCount + ")");
        //            System.out.println("***");
        //            System.out.println();

        classStartRow = currentExcelRow;
        XSSFRow row = sheet.createRow(currentExcelRow);
        XSSFCell cell = row.createCell(0);
        cell.setCellValue(clazz);
        cell.getCellStyle().setAlignment(CellStyle.ALIGN_CENTER);

        queryString = bindQueryString(classPropertyQueryString,
                ImmutableMap.of(IRI_BINDINGS, iriMap, LITERAL_BINDINGS, litMap));

        List<RDFNode> nodeList = executeQueryForList(queryString, endpoint, "p");

        for (RDFNode property : nodeList) {
            if (property.isURIResource()) {

                String propertyURI = property.asResource().getURI();
                //                    System.out.println("* " + propertyURI);
                //                    System.out.println();

                XSSFRow propertyRow = sheet.getRow(currentExcelRow);
                if (propertyRow == null) {
                    propertyRow = sheet.createRow(currentExcelRow);
                }
                currentExcelRow++;

                XSSFCell propertyCell = propertyRow.createCell(1);
                propertyCell.setCellValue(propertyURI);

                //                    System.out.println("| Min Card. |Max Card. |");
                //                    System.out.println("|---|---|");
                //                    System.out.println("| ? | ? |");
                //                    System.out.println();

            }
        }

        //System.out.println("class start: " + classStartRow + ", class end: " + (currentExcelRow -1));
        //We have finished writting properties of one class, now it's time to merge the cells
        int classEndRow = currentExcelRow - 1;
        if (classStartRow < classEndRow) {
            sheet.addMergedRegion(new CellRangeAddress(classStartRow, classEndRow, 0, 0));
        }

    }

    String filename = "test.xls";
    FileOutputStream fileOut = new FileOutputStream(filename);
    wb.write(fileOut);
    fileOut.close();

}

From source file:exportToExcel.ResultSetToExcelTest.java

License:Open Source License

public void Test() {

    XSSFWorkbook xlsxWorkbook = new XSSFWorkbook();
    XSSFSheet xlsSheet = xlsxWorkbook.createSheet();
    short rowIndex = 1;

    ResultSet rs = null;//from  ww  w.  ja  v a 2s  .  c  o  m

    try {

        //Get the list of column names and store them as the first
        //row of the spreadsheet.
        ResultSetMetaData colInfo = rs.getMetaData();
        ArrayList<String> colNames = new ArrayList<>();
        XSSFRow titleRow = xlsSheet.createRow(rowIndex++);

        for (int i = 1; i <= colInfo.getColumnCount(); i++) {

            colNames.add(colInfo.getColumnName(i));
            titleRow.createCell((short) (i - 1)).setCellValue(new XSSFRichTextString(colInfo.getColumnName(i)));
            xlsSheet.setColumnWidth((short) (i - 1), (short) 4000);

        }

        //Save all the data from the database table rows

        while (rs.next()) {

            XSSFRow dataRow = xlsSheet.createRow(rowIndex++);

            short colIndex = 0;

            for (String colName : colNames) {
                dataRow.createCell(colIndex++).setCellValue(new XSSFRichTextString(rs.getString(colName)));
            }
        }

        //Write to disk

        xlsxWorkbook.write(new FileOutputStream("data.xlsx"));

    } catch (SQLException | IOException e) {

        System.exit(1);

    }

}