Example usage for org.apache.commons.csv CSVFormat EXCEL

List of usage examples for org.apache.commons.csv CSVFormat EXCEL

Introduction

In this page you can find the example usage for org.apache.commons.csv CSVFormat EXCEL.

Prototype

CSVFormat EXCEL

To view the source code for org.apache.commons.csv CSVFormat EXCEL.

Click Source Link

Document

Excel file format (using a comma as the value delimiter).

Usage

From source file:MasterRoomControllerFx.rooms.charts.RoomChartController.java

public void getHumData() {
    try {/*from ww w  .  ja  va 2  s.c  o  m*/
        File csvData = new File("humHistory" + roomRow + roomColumn + ".csv");
        if (csvData.exists()) {
            CSVParser parser = CSVParser.parse(csvData, StandardCharsets.UTF_8,
                    CSVFormat.EXCEL.withDelimiter(';'));
            for (CSVRecord csvRecord : parser) {
                for (int i = 0; i < csvRecord.size() - 1; i++) {
                    hum.add(Float.parseFloat(csvRecord.get(i)));
                }
            }
        }
    } catch (IOException ex) {
        Logger.getLogger(RoomChartController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:edu.clemson.lph.civet.addons.VspsCviFile.java

/**
 * Test only/* w  w w  . j  av  a2  s  .  c  o  m*/
 */
private void printme(File fIn) {
    try {
        CSVParser parserIn = new CSVParser(new FileReader(fIn), CSVFormat.EXCEL);
        parser = new LabeledCSVParser(parserIn);
        aCols = parser.getNext();
    } catch (FileNotFoundException e) {
        logger.error(e.getMessage() + "\nCould not read file: " + fIn.getName());
    } catch (IOException e) {
        logger.error(e.getMessage() + "\nCould not read file: " + fIn.getName());
    }
    VspsCvi cvi;
    try {
        while ((cvi = nextCVI()) != null) {
            if (cvi.getStatus().equals("SAVED"))
                continue;
            VspsCviEntity orig = cvi.getOrigin();
            VspsCviEntity dest = cvi.getDestination();
            System.out.println(cvi.getCVINumber() + " created: " + cvi.getCreateDate());
            System.out
                    .println("  origin = " + orig.getName() + " " + orig.getPhone() + " " + orig.getAddress1());
            System.out.println(
                    "  destination = " + dest.getName() + " " + dest.getPhone() + " " + dest.getAddress1());
            System.out.println(cvi.getOriginState() + " " + orig.getState());
            System.out.println(
                    cvi.getVeterinarianName() + ": " + cvi.getVetFirstName() + " " + cvi.getVetLastName());
            System.out.println(cvi.getAnimals().size() + " Animals in CVI");
            System.out.println(cvi.getRemarks());
            for (List<String> aKey : cvi.getSpecies().keySet()) {
                Integer iCount = cvi.getSpecies().get(aKey);
                System.out.println(iCount + " " + aKey.get(0) + " (" + aKey.get(1) + ")");
            }
            for (VspsCviAnimal animal : cvi.getAnimals()) {
                System.out.println("\t" + animal.getSpecies() + " " + animal.getBreed() + " "
                        + animal.getGender() + " " + animal.getDateOfBirth());
                for (int i = 1; i <= 5; i++) {
                    String sIdType = animal.getIdentifierType(i);
                    if (sIdType != null)
                        System.out.println("\t\t" + sIdType + " = " + animal.getIdentifier(i));
                }
            }
        }
    } catch (IOException e) {
        logger.error(e);
    }
}

From source file:br.edimarmanica.trinity.intrasitemapping.manual.OffsetToRule.java

private void print(String page, List<String> values) {
    File dir = new File(Paths.PATH_TRINITY + "/" + site.getPath() + "/extracted_values/");

    if (!append) {
        FileUtils.deleteDir(dir);// w w w  .  j ava2s. c  o  m
        dir.mkdirs();
    }

    for (int ruleID = 0; ruleID < values.size(); ruleID++) {

        File file = new File(dir.getAbsolutePath() + "/rule_" + ruleID + ".csv");
        CSVFormat format;
        if (append) {
            format = CSVFormat.EXCEL;
        } else {
            format = CSVFormat.EXCEL.withHeader(header);
        }

        try (Writer out = new FileWriter(file, append)) {
            try (CSVPrinter csvFilePrinter = new CSVPrinter(out, format)) {
                List<String> dataRecord = new ArrayList<>();
                dataRecord.add(page);
                dataRecord.add(values.get(ruleID));
                csvFilePrinter.printRecord(dataRecord);
            }
        } catch (IOException ex) {
            Logger.getLogger(Printer.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    append = true;
}

From source file:com.linkedin.pinot.core.data.readers.CSVRecordReader.java

private CSVFormat getFormatFromConfig() {
    String format = (_config != null) ? _config.getCsvFileFormat() : null;

    if (format == null) {
        return CSVFormat.DEFAULT;
    }//from  www. j ava 2 s  . c  om

    format = format.toUpperCase();
    if ((format.equals("DEFAULT"))) {
        return CSVFormat.DEFAULT;

    } else if (format.equals("EXCEL")) {
        return CSVFormat.EXCEL;

    } else if (format.equals("MYSQL")) {
        return CSVFormat.MYSQL;

    } else if (format.equals("RFC4180")) {
        return CSVFormat.RFC4180;

    } else if (format.equals("TDF")) {
        return CSVFormat.TDF;
    } else {
        return CSVFormat.DEFAULT;
    }
}

From source file:com.apkcategorychecker.writer.WriterCSV.java

@Override
public void createHeader(String _csvPath) throws IOException {
    /*--Create the CSVFormat object--*/

    CSVFormat format = CSVFormat.EXCEL.withHeader().withDelimiter(',');

    /*--Writing in a CSV file--*/

    File _fileCSV = new File(_csvPath);
    FileWriter _out;// www .  java  2  s  .com
    _out = new FileWriter(_fileCSV);
    CSVPrinter printer;
    printer = new CSVPrinter(_out, format.withDelimiter('#'));
    System.out.println("Creating the CSV file....");
    try {
        printer.printRecord("App_ID", "APK_File_Name", "APK_File_Path", "APK_Package", "Main_Framework",
                "Base_Framework", "HTML", "JS", "CSS", "Android_Debuggable", "Android_Permissions",
                "Android_MinSdkVersion", "Android_MaxSdkVersion", "Android_TargetSdkVersion",
                "File_Size(Bytes)", "Start_Analysis_Time(milliseconds)", "Duration_Analysis_Time(milliseconds)",
                "Decode_Success");
    } catch (IOException ex) {
        Logger.getLogger(WriterCSV.class.getName()).log(Level.SEVERE, null, ex);
    }
    printer.close();

}

From source file:edu.uri.egr.hermes.manipulators.FileLog.java

private void writeHeaders() {
    try {//from  www .  jav a 2s .  c o m
        CSVFormat.EXCEL.withHeader(headers).print(new BufferedWriter(new FileWriter(file))).close();
    } catch (IOException e) {
        Timber.e("Failed to log: %s", e.getMessage());
    }
}

From source file:com.edu.duke.URLResource.java

/**
 * Returns a <code>CSVParser</code> object to access the contents of an open web page, possibly
 * without a header row and a different data delimiter than a comma.
 * /*from  www. ja  va 2  s . co  m*/
 * Each line of the web page should be formatted as data separated by the delimiter passed as a
 * parameter and with/without a header row to describe the column names. This is useful if the
 * data is separated by some character other than a comma.
 * 
 * @param withHeader uses first row of data as a header row only if true
 * @param delimiter a single character that separates one field of data from another
 * @return a <code>CSVParser</code> that can provide access to the records in the web page one
 *         at a time
 */
public CSVParser getCSVParser(boolean withHeader, String delimiter) {
    if (delimiter == null || delimiter.length() != 1) {
        throw new ResourceException("URLResource: CSV delimiter must be a single character: " + delimiter);
    }
    try {
        char delim = delimiter.charAt(0);
        Reader input = new StringReader(mySource);
        if (withHeader) {
            return new CSVParser(input, CSVFormat.EXCEL.withHeader().withDelimiter(delim));
        } else {
            return new CSVParser(input, CSVFormat.EXCEL.withDelimiter(delim));
        }
    } catch (Exception e) {
        throw new ResourceException("URLResource: cannot read " + myPath + " as a CSV file.");
    }
}

From source file:edu.washington.gs.skyline.model.quantification.QuantificationTest.java

private List<InputRecord> readInputRecords(String filename) throws Exception {
    List<InputRecord> list = new ArrayList<>();
    Reader reader = new InputStreamReader(QuantificationTest.class.getResourceAsStream(filename));
    try {/*from   w  ww.j av a 2s . c  om*/
        CSVParser parser = new CSVParser(reader, CSVFormat.EXCEL.withHeader());
        for (CSVRecord record : parser.getRecords()) {
            list.add(new InputRecord(record));
        }

    } finally {
        reader.close();
    }
    return list;
}

From source file:com.coverity.report.analysis.ProtecodeSCToolProcessor.java

@Override
public void readData() throws ToolProcessorException {
    componentsDataList = restService.getComponentsInfo(config.productId);

    vulnerabilitiesDataList = restService.getVulnerabilitiesInfo(config.productId);

    systemInfo = restService.getSystemInfo();

    productScan = restService.getProductScanResult(config.productId);
    try {//from  www  .ja  v a  2 s. c  o  m
        File componentsTempFile = File.createTempFile(Personality.getInstance().tempFileNameBase(), ".csv");
        File vulnerabilitiesTempFile = File.createTempFile(Personality.getInstance().tempFileNameBase(),
                ".csv");

        String[] componentsHeadings = new String[] { "component name", "version", "license", "license type",
                "vulnerability count", "object" };
        try (FileWriter writer = new FileWriter(componentsTempFile)) {
            CSVPrinter printer = new CSVPrinter(writer, CSVFormat.EXCEL);
            printer.printRecord(componentsHeadings);
            componentsDataList.stream().forEach(info -> {
                String[] componentsRecord = new String[componentsHeadings.length];
                componentsRecord[0] = info.getComponent();
                componentsRecord[1] = info.getVersion();
                componentsRecord[2] = info.getLicense();
                componentsRecord[3] = info.getLicenseType();
                componentsRecord[4] = String.valueOf(info.getVulnerabilityCount());
                componentsRecord[5] = info.getObject();
                try {
                    printer.printRecord(componentsRecord);
                } catch (Exception ignored) {
                }

            });
            dataFiles.add(new DataFile("protecode-components.csv", componentsTempFile));
        } catch (IOException e) {
            throw makeException("Could not write protecode components data to CSV file "
                    + componentsTempFile.getAbsolutePath(), e);
        }

        String[] vulnerabilitiesHeadings = new String[] { "component", "version", "CVE", "CVSS" };
        try (FileWriter writer = new FileWriter(vulnerabilitiesTempFile)) {
            CSVPrinter printer = new CSVPrinter(writer, CSVFormat.EXCEL);
            printer.printRecord(vulnerabilitiesHeadings);
            vulnerabilitiesDataList.stream().forEach(info -> {
                String[] vulnerabilitiesRecord = new String[vulnerabilitiesHeadings.length];
                vulnerabilitiesRecord[0] = info.getComponent();
                vulnerabilitiesRecord[1] = info.getVersion();
                vulnerabilitiesRecord[2] = info.getCve();
                vulnerabilitiesRecord[3] = String.valueOf(info.getCvss());
                try {
                    printer.printRecord(vulnerabilitiesRecord);
                } catch (Exception ignored) {
                }

            });
            dataFiles.add(new DataFile("protecode-vulnerabilities.csv", vulnerabilitiesTempFile));
        } catch (IOException e) {
            throw makeException("Could not write protecode vulnerabilities to CSV file "
                    + vulnerabilitiesTempFile.getAbsolutePath(), e);
        }
    } catch (IOException e) {
        throw makeException("Cannot create temporary file", e);
    }
}

From source file:edu.washington.gs.skyline.model.quantification.QuantificationTest.java

private Map<RecordKey, Double> readExpectedRows(String filename) throws Exception {
    Map<RecordKey, Double> map = new HashMap<>();
    Reader reader = new InputStreamReader(QuantificationTest.class.getResourceAsStream(filename));
    try {/*from  ww w. jav  a  2  s . c  o m*/
        CSVParser parser = new CSVParser(reader, CSVFormat.EXCEL.withHeader());
        for (CSVRecord record : parser.getRecords()) {
            map.put(new RecordKey(record), parseNullableDouble(record.get("NormalizedArea")));
        }
    } finally {
        reader.close();
    }
    return map;
}