Example usage for org.apache.poi.xssf.usermodel XSSFWorkbook write

List of usage examples for org.apache.poi.xssf.usermodel XSSFWorkbook write

Introduction

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

Prototype

@SuppressWarnings("resource")
public final void write(OutputStream stream) throws IOException 

Source Link

Document

Write out this document to an Outputstream.

Usage

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 w w  .  j a  v  a  2s. 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 a  2 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 {/*from  w  w  w .j  a v  a 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()) {

                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 {/* www .  j  a  va2 s .c  o  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:eventHandlers.CompareDrotVSRoster.java

public void colorXLSXFile(String leaveXlsxRoster) throws FileNotFoundException, IOException {
    File xlsxFile = new File(leaveXlsxRoster);
    try {/*from  ww  w  .j ava  2  s . c o m*/
        FileInputStream fis = new FileInputStream(xlsxFile);
        XSSFWorkbook myWorkBook = new XSSFWorkbook(fis);

        //Return first sheet from the XLSX workbook
        XSSFSheet mySheet = myWorkBook.getSheetAt(0);

        //Get iterator to all the rows in current sheet
        Iterator<Row> rowIterator = mySheet.iterator();
        // Traversing over each row of XLSX file
        if (rowIterator.hasNext()) {
            Row headerRow = rowIterator.next(); //skip the header row
            Iterator<Cell> it = headerRow.cellIterator();
            int numCell = 0;
            // List<String> keyList = new ArrayList<>(); //keep track info of each column
            while (it.hasNext()) {
                //keyList.add(it.next().getStringCellValue());   
                it.next();
                numCell++;
            }

            if (numCell == GlobalVar.SIGNED_LEAVE_TITLES.length) { // correct xlsx file                 
                int rowNum = 1;
                while (rowIterator.hasNext()) {
                    Row row = rowIterator.next();
                    //row.getRowStyle();
                    rowNum++;
                }
                for (int i = 1; i < rowNum; i++) {
                    Row row = mySheet.getRow(i);
                    foregroundColorSetUp(row, myWorkBook); //check each row and update foreground color
                }
                fis.close();
                FileOutputStream output;
                String targetFile = null;
                String[] names = leaveXlsxRoster.split("\\.");
                if (!names[0].equals(leaveXlsxRoster)) { //doesn't contain surfix
                    targetFile = names[0] + "COLORED.xlsx";
                } else {
                    targetFile = leaveXlsxRoster + "COLORED.xlsx";
                }
                output = new FileOutputStream(targetFile);
                myWorkBook.write(output);
                output.close();
                //myWorkBook.write(output);

            } else {
                JOptionPane.showMessageDialog(null, "XLSX file doesn't contain correct info!");
            }
        } else {
            JOptionPane.showMessageDialog(null, "XLSX file is empty!");
            System.out.println("The xlsx file is empty!");
        }

        // finds the work book in stance for XLSX file
    } catch (FileNotFoundException ex) {
        JOptionPane.showMessageDialog(null, "Xlsx file not found!");
    }
}

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;// w  ww  .ja v a2 s.  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);

    }

}

From source file:File.XLSX.CreateXLSX.java

public void CreateNew(String data, int Frow, int Fcol, String path, String namafile) {
    //Blank workbook
    XSSFWorkbook workbook = new XSSFWorkbook();

    //Create a blank sheet
    XSSFSheet sheet = workbook.createSheet("sheet 1");

    int rownum = Frow;
    String[] split_row = data.split(";");
    for (String data_row : split_row) {
        int cellnum = Fcol;
        Row row = sheet.createRow(rownum++);
        String[] split_cols = data_row.split(",");
        for (String data_cols : split_cols) {
            Cell cell = row.createCell(cellnum++);
            cell.setCellValue(data_cols);
        }//ww w .  j  a v a 2  s  .c o  m
    }
    try {
        //Write the workbook in file system
        File file = new File(path + namafile + ".xlsx");
        FileOutputStream out = new FileOutputStream(file);
        workbook.write(out);
        out.close();
        System.out.println("Berhasil membuat file");

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

From source file:FileHelper.ExcelHelper.java

private void WriteResultTestCaseForSheet(String fileName, String sheetName, DataTestCaseFull data) {
    try {/*w w w.jav a2  s.  c o m*/
        File excel = new File(fileName);
        FileInputStream fis = new FileInputStream(excel);
        XSSFWorkbook book = new XSSFWorkbook(fis);
        XSSFSheet sheet = book.getSheet(sheetName);
        for (RowDataFromFile dataRow : data.getDatas().getDatas()) {
            Row row = sheet.getRow(dataRow.getId());
            Cell cell = row.getCell(dataRow.getNumReal());
            if (cell == null) {
                cell = row.createCell(dataRow.getNumReal());
            }
            if (dataRow.getResultReal() != null) {
                cell.setCellValue(dataRow.getResultReal());
            }
        }
        fis.close();

        FileOutputStream fos = new FileOutputStream(new File(fileName));
        book.write(fos);
        fos.close();
    } catch (Exception t) {
        System.out.println("Throwable WriteResultTestCaseForSheet " + t.getMessage());
    }
}

From source file:FileHelper.ExcelHelper.java

private void CreateFileResultThread(String fileName) {
    try {/*  w w w . jav a2  s .c  o  m*/
        File excel = new File(fileName);
        if (excel.exists()) {
            excel.delete();
        }
        FileOutputStream fos = new FileOutputStream(new File(fileName));
        XSSFWorkbook book = new XSSFWorkbook();
        XSSFSheet sheet = book.createSheet("sheet1");
        book.write(fos);
        fos.close();
    } catch (Exception t) {
        System.out.println("Throwable CreateFileResultThread " + t.getMessage());
    }
}

From source file:FileHelper.ExcelHelper.java

private void CreateSheetResult(ThreadResult threadR) {
    try {/*from   w w w . j a  v a2 s.co  m*/
        File excel = new File("result_threads.xlsx");
        FileInputStream fis = new FileInputStream(excel);
        XSSFWorkbook book = new XSSFWorkbook(fis);
        XSSFSheet sheet = book.createSheet(threadR.getNameSheet());
        // Create Tile Tile
        Row row = sheet.createRow(0);
        Cell cell = row.createCell(0);
        cell.setCellValue("ID");
        cell = row.createCell(1);
        cell.setCellValue("Code Result");
        cell = row.createCell(2);
        cell.setCellValue("Response Time (ms)");
        //
        for (int i = 0; i < threadR.getThreads().size(); i++) {
            Row row1 = sheet.createRow(i + 1);
            Cell cell1 = row1.createCell(0);
            cell1.setCellValue(i + 1);

            cell1 = row1.createCell(1);
            cell1.setCellValue(threadR.getThreads().get(i).getCode());

            cell1 = row1.createCell(2);
            cell1.setCellValue(threadR.getThreads().get(i).getTime());
        }
        fis.close();
        FileOutputStream fos = new FileOutputStream(new File("result_threads.xlsx"));
        book.write(fos);
        fos.close();
    } catch (Exception t) {
        System.out.println("Throwable CreateSheetResult " + t.getMessage());
    }
}