on 04-11-2005 8:34 AM
Hi to all,
I downloaded the content of a table to a CSV file using a code like this:
IWDAttributeInfo attInfo = wdContext.nodeDownload().getNodeInfo().getAttribute("TableDownload");
IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType) attInfo.getModifiableSimpleType();
binaryType.setFileName("Table.csv");
binaryType.setMimeType(WDWebResourceType.UNKNOWN);
ByteArrayOutputStream outStr = new ByteArrayOutputStream();
for (int Cntr = 0;Cntr < wdContext.nodeTable().size();Cntr++) {
wdContext.nodeTable().moveTo(Cntr);
byte[] NEW_LINE = "\n".getBytes();
byte[] Part = wdContext.currentListaElement().getfirstcolumn().getBytes();
outStr.write( Part, 0, Part.length );
outStr.write((byte)sep);
Part = wdContext.currentListaElement().getsecondcolumn().getBytes();
outStr.write(Part, 0, Part.length);
outStr.write((byte)sep);
}
wdContext.currentDownloadElement().setListaDownload(outStr.toByteArray());
wdContext.nodeTable().moveTo(0);
It works fine, but I have a problem with commas. I come from Italy and here usually the symbol for decimal separator is comma. But one column of my table (to download) is a description that can have commas in it. So when I download to CSV file, it results separated in a wrong way.
I don't know if I was clear, sorry.
How can I do? Can I download directly to XLS file or a TXT file?
Thank you very much for your help,
Antonio
Hi Antonio,
There is a API called jxl which is readily available in the net.You can use it to write data into excel file.I wil just give you a sample code.Check with it after u download the API .Your problem shud be solved then.
file = new File(filename.xls");
WorkBook workbook = Workbook.createWorkbook(file); WritableSheet sheet =workbook.createSheet("sheet name",0);
WritableCell cell = sheet.getWritableCell(0,0);
In the code
after getting the data ..say
data = wdContext.currentListaElement().getfirstcolumn().....
place this as the argument for the cell...as shown
sheet.addCell(new Label(0,0,"data"));
Label(row,column,data)....is the format.
and finally
workbook.write();
If this does not work out check these links...
http://www.andykhan.com/jexcelapi/tutorial.html#writing
or
/people/prakash.singh4/blog/2005/03/16/create-an-excel-file-from-java-using-hssf-api
Regards
Bharathwaj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
82 | |
10 | |
10 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.