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

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

Introduction

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

Prototype

public XSSFWorkbook(PackagePart part) throws IOException 

Source Link

Document

Constructs a XSSFWorkbook object using Package Part.

Usage

From source file:com.dataart.spreadsheetanalytics.test.util.GraphTestUtil.java

License:Apache License

protected static void generateGraphmlFilesetAllCells(boolean all, ExecutionGraphConfig config)
        throws Exception {
    System.out.println("Begin. Fileset.");

    String testTemplate = null;// w ww. j  a va2  s  .co m
    try (FileInputStream fis = new FileInputStream(TEST_CLASS_TEMPLATE_ALL)) {
        byte[] b = new byte[fis.available()];
        fis.read(b);
        testTemplate = new String(b);
    }

    try (Scanner sc = new Scanner(Paths.get(GRAPH_PATHS_FILE_ALL))) {

        System.out.println("For each line in file [" + GRAPH_PATHS_FILE_ALL + "]\n");
        while (sc.hasNext()) {
            String line = sc.next();

            String path = STANDARD_EXCELS_DIR + line + ".xlsx";
            String filename = ALL_CELLS_GRAPHML_DIR + line + "/" + graphConfigToString.get(config) + ".graphml";

            if (!all && Files.exists(Paths.get(filename))) {
                continue;
            }

            System.out.println("Excel file [" + path + "], address [" + "All" + "]");

            final IDataModel model = Converters.toDataModel(new XSSFWorkbook(path));

            initExternalServices(model);

            final IAuditor auditor = new SpreadsheetAuditor(model);

            final IExecutionGraph<IExecutionGraphVertex, IExecutionGraphEdge> graph = auditor
                    .buildExecutionGraph(config);

            File file = new File(ALL_CELLS_GRAPHML_DIR + line + "/");
            file.mkdirs();
            Writer fw = new FileWriter(filename);

            ExecutionGraphMLExporter exporter = new ExecutionGraphMLExporter(
                    graphConfigToString.get(config).substring(1));
            exporter.export(fw, graph);

            System.out.println("GraphML file is written to [" + filename + "]");
            System.out.println("Number of Vertices : " + graph.getVertices().size());

            generateVisualizer(graph, VISUALIZER_STANDARDWITHCONFIG_DATA_JS_FILES, line,
                    graphConfigToString.get(config));
            System.out.println("Visualizer files as written to [" + VISUALIZER_STANDARDWITHCONFIG_DATA_JS_FILES
                    + line + "_" + graphConfigToString.get(config) + "].");

            String testFile = testTemplate.replace("[FILENAME]", line).replace("XXX", line + "_" + "All");

            try (OutputStream fos = new FileOutputStream(
                    TEST_CLASS_FILE_ALL.replace("XXX", line + "_" + "All"))) {
                fos.write(testFile.getBytes());
            }

            System.out.println("Java Test file is written to ["
                    + TEST_CLASS_FILE_ALL.replace("XXX", line + "_" + "All") + "]");
            System.out.println();

            GraphTestUtil.destroyExternalServices();
        }
    }
    System.out.println("\nEnd. Fileset.");
}

From source file:com.dataart.spreadsheetanalytics.test.util.GraphTestUtil.java

License:Apache License

public static void generateGraphmlFileset(boolean all) throws Exception {
    System.out.println("Begin. Fileset.");

    String testTemplate = null;/*  www.ja v a2 s .  c o  m*/
    try (FileInputStream fis = new FileInputStream(TEST_CLASS_TEMPLATE)) {
        byte[] b = new byte[fis.available()];
        fis.read(b);
        testTemplate = new String(b);
    }

    try (Scanner sc = new Scanner(Paths.get(GRAPH_PATHS_FILE))) {

        System.out.println("For each line in file [" + GRAPH_PATHS_FILE + "]\n");
        while (sc.hasNext()) {
            String[] line = sc.next().split("\\$");

            String path = STANDARD_EXCELS_DIR + line[0] + ".xlsx";
            String address = line[1];
            String filename = STANDARD_GRAPHML_DIR + line[0] + "_" + address + ".graphml";

            if (!all && Files.exists(Paths.get(filename))) {
                continue;
            }

            System.out.println("Excel file [" + path + "], address [" + address + "]");

            final IDataModel model = Converters.toDataModel(new XSSFWorkbook(path));

            initExternalServices(model);

            final IAuditor auditor = new SpreadsheetAuditor(model);
            final ICellAddress addr = new CellAddress(model.getDataModelId(), A1Address.fromA1Address(address));

            final IExecutionGraph<IExecutionGraphVertex, IExecutionGraphEdge> graph = auditor
                    .buildExecutionGraph(addr.a1Address());

            Writer fw = new FileWriter(filename);

            ExecutionGraphMLExporter exporter = new ExecutionGraphMLExporter(address);
            exporter.export(fw, graph);

            System.out.println("GraphML file is written to [" + filename + "]");
            System.out.println("Number of Vertices : " + graph.getVertices().size());

            generateVisualizer(graph, VISUALIZER_STANDARD_DATA_JS_FILES, line[0], address);
            System.out.println("Visualizer files as written to [" + VISUALIZER_STANDARD_DATA_JS_FILES + line[0]
                    + address + "].");

            String testFile = testTemplate.replace("[CELL_ADDRESS]", address).replace("[FILENAME]", line[0])
                    .replace("XXX", line[0] + "_" + address);
            try (FileOutputStream fos = new FileOutputStream(
                    TEST_CLASS_FILE.replace("XXX", line[0] + "_" + address))) {
                fos.write(testFile.getBytes());
            }
            System.out.println("Java Test file is written to ["
                    + TEST_CLASS_FILE.replace("XXX", line[0] + "_" + address) + "]");
            System.out.println();
            GraphTestUtil.destroyExternalServices();
        }
    }
    System.out.println("\nEnd. Fileset.");
}

From source file:com.dataart.spreadsheetanalytics.test.util.GraphTestUtil.java

License:Apache License

public static void generateGraphmlFile(String excelFile, String excelAddress) throws Exception {
    System.out.println("Begin. One file.\nFor file [" + excelFile + "] and address [" + excelAddress + "]\n");

    String path = STANDARD_EXCELS_DIR + excelFile + ".xlsx";
    String address = excelAddress;
    String filename = STANDARD_GRAPHML_DIR + excelFile + "_" + address + ".graphml";

    System.out.println("Excel file [" + path + "], address [" + address + "]");

    final IDataModel model = Converters.toDataModel(new XSSFWorkbook(path));

    initExternalServices(model);//w  ww.  j a  v a2  s. com

    final IAuditor auditor = new SpreadsheetAuditor(model);
    final ICellAddress addr = new CellAddress(model.getDataModelId(), A1Address.fromA1Address(address));

    final IExecutionGraph<IExecutionGraphVertex, IExecutionGraphEdge> graph = auditor
            .buildExecutionGraph(addr.a1Address());

    Writer fw = new FileWriter(filename);

    ExecutionGraphMLExporter exporter = new ExecutionGraphMLExporter(address);
    exporter.export(fw, graph);

    System.out.println("GraphML file is written to [" + filename + "]\n\nEnd. One file.");
    System.out.println("Number of Vertices : " + graph.getVertices().size());

    generateVisualizer(graph, VISUALIZER_STANDARD_DATA_JS_FILES, excelFile, address);
    System.out.println("Visualizer files as written to [" + VISUALIZER_STANDARD_DATA_JS_FILES + excelFile
            + address + "]\n\nEnd. One file.");

    destroyExternalServices();
}

From source file:com.dataart.spreadsheetanalytics.test.util.GraphTestUtil.java

License:Apache License

public static void generateGraphmlFile(String excelFile, ExecutionGraphConfig config) throws Exception {
    System.out.println("Begin. One file. All cells.\nFor file [" + excelFile + "] \n");

    String suffix = graphConfigToString.get(config);

    String path = STANDARD_EXCELS_DIR + excelFile + ".xlsx";
    String filename = ALL_CELLS_GRAPHML_DIR + excelFile + "/" + graphConfigToString.get(config) + ".graphml";

    System.out.println("Excel file [" + path + "], All cells");

    final IDataModel model = Converters.toDataModel(new XSSFWorkbook(path));

    initExternalServices(model);//from   ww w .j  a va  2 s .  c om

    final IAuditor auditor = new SpreadsheetAuditor(model);

    final IExecutionGraph<IExecutionGraphVertex, IExecutionGraphEdge> graph = auditor
            .buildExecutionGraph(config);

    Writer fw = new FileWriter(filename);

    ExecutionGraphMLExporter exporter = new ExecutionGraphMLExporter(suffix.substring(1) + "_");
    exporter.export(fw, graph);

    System.out.println("GraphML file is written to [" + filename + "]");
    System.out.println("Number of Vertices : " + graph.getVertices().size());

    generateVisualizer(graph, VISUALIZER_STANDARDWITHCONFIG_DATA_JS_FILES, excelFile, suffix);
    System.out.println("Visualizer files as written to [" + VISUALIZER_STANDARDWITHCONFIG_DATA_JS_FILES
            + excelFile + suffix + "]\n\nEnd. One file.");

    destroyExternalServices();
}

From source file:com.dataart.spreadsheetanalytics.test.util.GraphTestUtil.java

License:Apache License

public static void generateGraphmlFilesAdvJoin() throws Exception {
    System.out.println("Begin. Fileset.");
    for (ExecutionGraphConfig config : graphConfigToString.keySet()) {
        try (Scanner sc = new Scanner(Paths.get(ADV_GRAPH_PATHS_FILE_ALL))) {

            System.out.println("For each line in file [" + ADV_GRAPH_PATHS_FILE_ALL + "]\n");
            while (sc.hasNext()) {
                String line = sc.next();

                String path = ADVANCED_CONF_TESTS_EXCEL_DIR + line + ".xlsx";
                String filename = ADVANCED_CONF_TESTS_DIR + line + "/" + graphConfigToString.get(config)
                        + ".graphml";

                System.out.println("Excel file [" + path + "], address [" + "All" + "]");

                final IDataModel model = Converters.toDataModel(new XSSFWorkbook(path));

                initExternalServices(model);

                final IAuditor auditor = new SpreadsheetAuditor(model);

                final IExecutionGraph graph = auditor.buildExecutionGraph(config);

                File file = new File(ADVANCED_CONF_TESTS_DIR + line + "/");
                file.mkdirs();/*  w  ww  . j  a  va 2  s .  c o  m*/
                Writer fw = new FileWriter(filename);

                ExecutionGraphMLExporter exporter = new ExecutionGraphMLExporter(
                        graphConfigToString.get(config).substring(1));
                exporter.export(fw, graph);

                System.out.println("GraphML file is written to [" + filename + "]");
                System.out.println("Number of Vertices : " + graph.getVertices().size());

                generateVisualizer(graph, VISUALIZER_STANDARDWITHCONFIG_DATA_JS_FILES, line,
                        graphConfigToString.get(config));
                System.out.println(
                        "Visualizer files as written to [" + VISUALIZER_STANDARDWITHCONFIG_DATA_JS_FILES + line
                                + "_" + graphConfigToString.get(config) + "].");

                System.out.println("Java Test file is written to ["
                        + TEST_CLASS_FILE_ALL.replace("XXX", line + "_" + "All") + "]");
                System.out.println();

                GraphTestUtil.destroyExternalServices();
            }
        }
    }
    System.out.println("\nEnd. Fileset.");
}

From source file:com.ddt.driver.EXCELDriver.java

private void readNewerVersionExcelFile(String path, String sheetName) {
    try {/*www. j  ava  2  s  .  c o m*/
        try (final FileInputStream file = new FileInputStream(new File(path))) {
            XSSFWorkbook workbook = new XSSFWorkbook(file);
            XSSFSheet sheet = getSheetName(sheetName, workbook);
            Iterator<Row> rowIterator = sheet.iterator();

            while (rowIterator.hasNext()) {
                String line = "";
                Row row = rowIterator.next();
                Iterator<Cell> cellIterator = row.cellIterator();

                while (cellIterator.hasNext()) {
                    Cell cell = cellIterator.next();

                    switch (cell.getCellType()) {
                    case Cell.CELL_TYPE_BOOLEAN:
                        line += cell.getBooleanCellValue() + ";";
                        break;
                    case Cell.CELL_TYPE_NUMERIC:
                        line += String.valueOf(cell.getNumericCellValue()).split("\\.")[0] + ";";
                        break;
                    case Cell.CELL_TYPE_STRING:
                        line += cell.getStringCellValue() + ";";
                        break;
                    }
                }
                linesOfDriver.add(line);
            }
        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(EXCELDriver.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(EXCELDriver.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.delpac.bean.CargarSellosBean.java

public void uploadFileList() {
    Workbook workbook = null;//from  w  ww .  j a v  a  2 s .c o  m
    for (FileUploaded fu : uploadedFilesList) {
        try {
            switch (fu.getExtension()) {
            case "xls":
                workbook = new HSSFWorkbook(fu.getFileInputStream());
                break;
            case "xlsx":
                workbook = new XSSFWorkbook(fu.getFileInputStream());
                break;
            }
            setListadoSellos(verifyFromExcel(importData(workbook, 0)));
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
    if (cantidadSellosRepetidos != 0) {
        FacesContext context = FacesContext.getCurrentInstance();
        String texto = "El listado cargado contiene " + cantidadSellosRepetidos
                + " elementos repetidos. Por favor verifica.";
        context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Atencin", texto));
    }
    uploadedFilesList.clear();
}

From source file:com.delpac.bean.PreDescargaBean.java

public void uploadFileList() {
    Workbook workbook = null;/*  www  .j av a  2  s.  c o m*/
    for (FileUploaded fu : uploadedFilesList) {
        try {
            switch (fu.getExtension()) {
            case "xls":
                workbook = new HSSFWorkbook(fu.getFileInputStream());
                break;
            case "xlsx":
                workbook = new XSSFWorkbook(fu.getFileInputStream());
                break;
            }
            setListadoPreDescarga(importData(workbook, 0));
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
        }
    }
    uploadedFilesList.clear();
}

From source file:com.denimgroup.threadfix.csv2ssl.parser.CSVToSSVLParser.java

License:Mozilla Public License

public static String parseExcel(File file, String... format) {
    try {//ww w.  jav a  2s  .  c  om
        FileInputStream fis = new FileInputStream(file);
        XSSFWorkbook wb = new XSSFWorkbook(fis);

        return RecordToXMLSerializer.getFromExcel(wb, format);
    } catch (IOException e) {
        throw new IllegalStateException("Received IOException while parsing file.", e);
    }
}

From source file:com.denimgroup.threadfix.csv2ssl.parser.FormatParser.java

License:Mozilla Public License

public static Option<String[]> getHeadersExcel(File file) {
    try {//from  w  ww .  j  a v  a2 s.c  om
        FileInputStream fis = new FileInputStream(file);
        XSSFWorkbook wb = new XSSFWorkbook(fis);

        XSSFSheet ws = wb.getSheetAt(0); // read the first sheet
        int totalRows = ws.getLastRowNum();

        if (totalRows == 0) {
            return Option.failure("No lines found in file " + file.getName());
        }

        XSSFRow row = ws.getRow(0);

        String[] headers = new String[row.getLastCellNum()];

        for (int index = 0; index < row.getLastCellNum(); index++) {
            XSSFCell cell = row.getCell(index);

            assert cell != null : "Got null cell at index " + index;

            headers[index] = cell.toString();
        }

        return Option.success(headers);

    } catch (IOException e) {
        e.printStackTrace();
        return Option.failure("Encountered IOException.");
    }
}