Java Code Examples for com.opencsv.CSVWriter#DEFAULT_QUOTE_CHARACTER

The following examples show how to use com.opencsv.CSVWriter#DEFAULT_QUOTE_CHARACTER . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CsvFormatter.java    From yarg with Apache License 2.0 6 votes vote down vote up
protected void writeCsvDocument(BandData rootBand, OutputStream outputStream) {
    try {
        List<BandData> actualData = getActualData(rootBand);
        CSVWriter writer = new CSVWriter(new OutputStreamWriter(outputStream), separator, CSVWriter.DEFAULT_QUOTE_CHARACTER);

        writer.writeNext(header);

        for (BandData row : actualData) {
            String[] entries = new String[parametersToInsert.size()];
            for (int i = 0; i < parametersToInsert.size(); i++) {
                String parameterName = parametersToInsert.get(i);
                String fullParameterName = row.getName() + "." + parameterName;
                entries[i] = formatValue(row.getData().get(parameterName), parameterName, fullParameterName);
            }
            writer.writeNext(entries);
        }

        writer.close();
    } catch (IOException e) {
        throw new ReportFormattingException("Error while writing a csv document", e);
    }
}
 
Example 2
Source File: SpreadsheetExporter.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
CsvExporter(String title, String gradeType, String csvSep) {
    gradesBAOS = new ByteArrayOutputStream();
    OutputStreamWriter osw = new OutputStreamWriter(gradesBAOS, Charset.forName("UTF-8"));
    try {
        osw.write(BOM);
    } catch (IOException e) {
        // tried
    }
    gradesBuffer = new CSVWriter(osw, csvSep.charAt(0), CSVWriter.DEFAULT_QUOTE_CHARACTER, CSVWriter.DEFAULT_ESCAPE_CHARACTER, CSVWriter.RFC4180_LINE_END);
    addRow(title, gradeType);
    addRow("");
}
 
Example 3
Source File: DownloadEventBean.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
private void csvSpreadsheet(OutputStream os, List<SignupMeetingWrapper> meetingWrappers) throws IOException {
	
	CSVExport export = new CSVExport(meetingWrappers, getSakaiFacade());

	
	CSVWriter writer = new CSVWriter(new OutputStreamWriter(os), ',', CSVWriter.DEFAULT_QUOTE_CHARACTER, CSVWriter.DEFAULT_ESCAPE_CHARACTER, downloadVersion);
	//header
	List<String> header = export.getHeaderRow();
	
	int cols = header.size(); //total number of columns is based on header row
	
	String[] headerRow = new String[cols];
	headerRow = header.toArray(headerRow);
	writer.writeNext(headerRow);
	
	//data rows
	List<List<String>> data = export.getDataRows();
	Iterator<List<String>> iter = data.iterator();
	while(iter.hasNext()) {
		List<String> row = iter.next();
		String[] dataRow = new String[cols];
		dataRow = row.toArray(dataRow);
		writer.writeNext(dataRow);
	}
	
	writer.close();
	
}
 
Example 4
Source File: SpreadsheetExporter.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
CsvExporter(String title, String gradeType, String csvSep) {
    gradesBAOS = new ByteArrayOutputStream();
    OutputStreamWriter osw = new OutputStreamWriter(gradesBAOS, Charset.forName("UTF-8"));
    try {
        osw.write(BOM);
    } catch (IOException e) {
        // tried
    }
    gradesBuffer = new CSVWriter(osw, csvSep.charAt(0), CSVWriter.DEFAULT_QUOTE_CHARACTER, CSVWriter.DEFAULT_ESCAPE_CHARACTER, CSVWriter.RFC4180_LINE_END);
    addRow(title, gradeType);
    addRow("");
}
 
Example 5
Source File: DownloadEventBean.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
private void csvSpreadsheet(OutputStream os, List<SignupMeetingWrapper> meetingWrappers) throws IOException {
	
	CSVExport export = new CSVExport(meetingWrappers, getSakaiFacade());

	
	CSVWriter writer = new CSVWriter(new OutputStreamWriter(os), ',', CSVWriter.DEFAULT_QUOTE_CHARACTER, CSVWriter.DEFAULT_ESCAPE_CHARACTER, downloadVersion);
	//header
	List<String> header = export.getHeaderRow();
	
	int cols = header.size(); //total number of columns is based on header row
	
	String[] headerRow = new String[cols];
	headerRow = header.toArray(headerRow);
	writer.writeNext(headerRow);
	
	//data rows
	List<List<String>> data = export.getDataRows();
	Iterator<List<String>> iter = data.iterator();
	while(iter.hasNext()) {
		List<String> row = iter.next();
		String[] dataRow = new String[cols];
		dataRow = row.toArray(dataRow);
		writer.writeNext(dataRow);
	}
	
	writer.close();
	
}
 
Example 6
Source File: XlsxFormatter.java    From yarg with Apache License 2.0 5 votes vote down vote up
protected void saveXlsxAsCsv(Document document, OutputStream outputStream) throws IOException, Docx4JException {
    CSVWriter writer = new CSVWriter(new OutputStreamWriter(outputStream), ';', CSVWriter.DEFAULT_QUOTE_CHARACTER);

    for (Document.SheetWrapper sheetWrapper : document.getWorksheets()) {
        Worksheet worksheet = sheetWrapper.getWorksheet().getContents();
        for (Row row : worksheet.getSheetData().getRow()) {
            String rows[] = new String[row.getC().size()];
            List<Cell> cells = row.getC();

            boolean emptyRow = true;
            for (int i = 0; i < cells.size(); i++) {
                checkThreadInterrupted();
                Cell cell = cells.get(i);
                String value = cell.getV();
                rows[i] = value;
                if (value != null && !value.isEmpty())
                    emptyRow = false;
            }

            if (!emptyRow)
                writer.writeNext(rows);
        }
    }
    writer.close();
}
 
Example 7
Source File: Driver.java    From access2csv with MIT License 5 votes vote down vote up
static int export(Database db, String tableName, Writer csv, boolean withHeader, boolean applyQuotesToAll, String nullText) throws IOException{
	Table table = db.getTable(tableName);
	String[] buffer = new String[table.getColumnCount()];
	CSVWriter writer = new CSVWriter(new BufferedWriter(csv), CSVWriter.DEFAULT_SEPARATOR, CSVWriter.DEFAULT_QUOTE_CHARACTER);
	int rows = 0;
	try{
		if (withHeader) {
			int x = 0;
			for(Column col : table.getColumns()){
				buffer[x++] = col.getName();
			}
			writer.writeNext(buffer, applyQuotesToAll);
		}
           
		for(Row row : table){
			int i = 0;
			for (Object object : row.values()) {
				buffer[i++] = object == null ? nullText : object.toString();
			}
			writer.writeNext(buffer, applyQuotesToAll);
			rows++;
		}
	}finally{
		writer.close();
	}
	return rows;
}
 
Example 8
Source File: DetailsActivity.java    From tracker-control-android with GNU General Public License v3.0 4 votes vote down vote up
protected Boolean doInBackground(final String... args) {
    if (exportDir == null) return false;

    File file = new File(exportDir, appPackageName + ".csv");
    try {
        file.createNewFile();
        CSVWriter csv = new CSVWriter(new FileWriter(file),
                CSVWriter.DEFAULT_SEPARATOR,
                CSVWriter.DEFAULT_QUOTE_CHARACTER,
                CSVWriter.DEFAULT_ESCAPE_CHARACTER,
                CSVWriter.RFC4180_LINE_END);

        Cursor data = trackerList.getAppInfo(appUid);
        if (data == null) return false;

        List<String> columnNames = new ArrayList<>();
        Collections.addAll(columnNames, data.getColumnNames());
        columnNames.add("Tracker Name");
        columnNames.add("Tracker Category");

        csv.writeNext(columnNames.toArray(new String[0]));
        while (data.moveToNext()) {
            String[] row = new String[data.getColumnNames().length + 2];
            for (int i = 0; i < data.getColumnNames().length; i++) {
                row[i] = data.getString(i);
            }

            String hostname = data.getString(data.getColumnIndex("daddr"));
            Tracker tracker = TrackerList.findTracker(hostname);
            if (tracker != null) {
                row[data.getColumnNames().length] = tracker.name;
                row[data.getColumnNames().length + 1] = tracker.category;
            } else {
                row[data.getColumnNames().length] = "";
                row[data.getColumnNames().length + 1] = "";
            }

            csv.writeNext(row);
        }
        csv.close();
        data.close();
    } catch (IOException e) {
        return false;
    }

    return true;
}