CSVWriter (?) <-- are there plans to offer?
Status: Beta
Brought to you by:
anupamsg
It would be nice if we were able to add a mapping such as "write-position" that if you were to offer a CSVWriter, that we would be able to send our bean to the CVSWriter to generate a CSV text file. This would be so convenient!!!
You might also offer a mapping at the top of the class "write-header" to determine whether to write the column headers to the first line.
tia. George
/**
* @return the docket
* @csv.field-mapping position="1" write-position="4"
*/
/**
* @author me
* @csv.bean-mapping bean-name="assets_and_LiabilitiesBean" csv-header="true" write-header="true"
*/
Logged In: NO
Hello,
I see ostermiller provides an excel (and non-excel) CSVPrinter class for writing csv files (see his test program below - though he seems to have forgotten to close his filestream with p.close()
However, I would still think very kind/relevant to your source project if you were to provide access to this functionality via field-mappings.
Of course, you would need to add one additional field mapping to the class so users can define the file path and file name. If user does not define, then write to System.out as ostermiller does below.
Finally, one additional field mapping to determine whether to utilize ostermiller's ExcelCSVPrinter or plain ole' CSVPrinter.
tia. George
private static void main (String[] args) {
OutputStream out;
try {
if (args.length > 0){
File f = new File(args[0]);
if (!f.exists()){
f.createNewFile();
if (f.canWrite()){
out = new FileOutputStream(f);
} else {
throw new IOException("Could not open " + args[0]);
}
} else {
throw new IOException("File already exists: " + args[0]);
}
} else {
out = System.out;
}
ExcelCSVPrinter p = new ExcelCSVPrinter(out);
p.print("unquoted");
p.print("escaped\"quote");
p.println("comma,comma");
p.print("!quoted");
p.print("!unquoted");
p.print(" quoted");
p.println("quoted ");
p.print("one");
p.print("");
p.print("");
p.print("");
p.println("");
p.println("two");
p.print("\nthree\nline\n");
p.println("\ttab");
} catch (IOException e){
System.out.println(e.getMessage());
}
}