本文整理汇总了Java中org.apache.commons.csv.CSVFormat.EXCEL属性的典型用法代码示例。如果您正苦于以下问题:Java CSVFormat.EXCEL属性的具体用法?Java CSVFormat.EXCEL怎么用?Java CSVFormat.EXCEL使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.commons.csv.CSVFormat
的用法示例。
在下文中一共展示了CSVFormat.EXCEL属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
public static void main(String[] args) throws IOException {
java.io.Writer writer = new java.io.OutputStreamWriter(new java.io.FileOutputStream(new File("/tmp/test.csv")), Charset.forName("UTF-8"));
CSVPrinter csvFilePrinter = new CSVPrinter(writer, CSVFormat.EXCEL);
java.util.List<Object> header = new java.util.ArrayList<Object>();
header.add("col1");
header.add("col2");
csvFilePrinter.printRecord(header);
csvFilePrinter.printRecord(header);
writer.close();
csvFilePrinter.close();
}
示例2: shouldUseFormatFromConstructor
@Test
public void shouldUseFormatFromConstructor() {
CsvDataFormat dataFormat = new CsvDataFormat(CSVFormat.EXCEL);
// Properly initialized
assertSame(CSVFormat.EXCEL, dataFormat.getFormat());
// Properly used
assertEquals(CSVFormat.EXCEL, dataFormat.getActiveFormat());
}
示例3: doCreateRouteBuilder
@Override
protected RouteBuilder doCreateRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
// get Report SObject by DeveloperName
from("direct:queryReport")
.to("salesforce:query?sObjectClass=" + QueryRecordsReport.class.getName());
from("direct:getRecentReports")
.to("salesforce:getRecentReports");
from("direct:getReportDescription")
.to("salesforce:getReportDescription");
from("direct:executeSyncReport")
.to("salesforce:executeSyncReport");
from("direct:executeAsyncReport")
.to("salesforce:executeAsyncReport?includeDetails=true");
from("direct:getReportInstances")
.to("salesforce:getReportInstances");
from("direct:getReportResults")
.to("salesforce:getReportResults");
CsvDataFormat csv = new CsvDataFormat(CSVFormat.EXCEL);
// type converter test
from("direct:convertResults")
.convertBodyTo(List.class)
.marshal(csv);
}
};
}
示例4: getCsvFormat
/**
* Returns a CSVFormat object given the CSV format as a string.
*
* @param format
* @return
*/
private CSVFormat getCsvFormat(String format) {
CSVFormat csvFormat = null;
switch (format.trim().toLowerCase()) {
case "default":
csvFormat = CSVFormat.DEFAULT;
break;
case "excel":
csvFormat = CSVFormat.EXCEL;
break;
case "informixunload":
case "informix-unload":
case "informix_unload":
csvFormat = CSVFormat.INFORMIX_UNLOAD;
break;
case "informixunloadcsv":
case "informix-unload-csv":
case "informix_unload_csv":
csvFormat = CSVFormat.INFORMIX_UNLOAD_CSV;
break;
case "mysql":
csvFormat = CSVFormat.MYSQL;
break;
case "postgres":
case "postgresql-csv":
case "postgresql_csv":
csvFormat = CSVFormat.POSTGRESQL_CSV;
break;
case "postgresql-text":
case "postgresql_text":
csvFormat = CSVFormat.POSTGRESQL_TEXT;
break;
case "rfc4180":
csvFormat = CSVFormat.RFC4180;
case "tdf":
csvFormat = CSVFormat.TDF;
default:
throw new RuntimeException(String.format("CSV format \"%s\" is not among the supported formats"));
}
return csvFormat;
}
示例5: CSVWriter
public CSVWriter() {
this(CSVFormat.EXCEL);
}
示例6: loadCSV
public static DataTable loadCSV(String fileName, String formatType, VariableType[] colTypesOverride, String[] colNamesOverride, boolean hasHeaderRow) {
try {
// use apache commons io + csv to load but convert to list of String[]
// byte-order markers are handled if present at start of file.
FileInputStream fis = new FileInputStream(fileName);
final Reader reader = new InputStreamReader(new BOMInputStream(fis), "UTF-8");
CSVFormat format;
if ( formatType==null ) {
format = hasHeaderRow ? CSVFormat.RFC4180.withHeader() : CSVFormat.RFC4180;
}
else {
switch ( formatType.toLowerCase() ) {
case "tsv":
format = hasHeaderRow ? CSVFormat.TDF.withHeader() : CSVFormat.TDF;
break;
case "mysql":
format = hasHeaderRow ? CSVFormat.MYSQL.withHeader() : CSVFormat.MYSQL;
break;
case "excel":
format = hasHeaderRow ? CSVFormat.EXCEL.withHeader() : CSVFormat.EXCEL;
break;
case "rfc4180":
default:
format = hasHeaderRow ? CSVFormat.RFC4180.withHeader() : CSVFormat.RFC4180;
break;
}
}
final CSVParser parser = new CSVParser(reader, format);
List<String[]> rows = new ArrayList<>();
int numHeaderNames = parser.getHeaderMap().size();
try {
for (final CSVRecord record : parser) {
String[] row = new String[record.size()];
for (int j = 0; j<record.size(); j++) {
row[j] = record.get(j);
}
rows.add(row);
}
}
finally {
parser.close();
reader.close();
}
VariableType[] actualTypes = computeColTypes(rows, numHeaderNames);
Set<String> colNameSet = parser.getHeaderMap().keySet();
String[] colNames = colNameSet.toArray(new String[colNameSet.size()]);
if ( colNamesOverride!=null ) {
colNames = colNamesOverride;
}
if ( colTypesOverride!=null ) {
actualTypes = colTypesOverride;
}
return fromStrings(rows, actualTypes, colNames, false);
}
catch (Exception e) {
throw new IllegalArgumentException("Can't open and/or read "+fileName, e);
}
}