I am a newbie to aspose. My requirements are very basic and I am looking for a sample that meets below requirement. I have a need to generate csv from a java object and write the csv to the output stream. Our company has aspose in-house and even though there are libraries to convert to csv (commoncsv etc.), I wanted to see if aspose can be used to meet this simple requirement. I do not want to save or generate excel files, just csv format data streamed out.
Hi,
Thanks for your posting and considering Aspose.Cells for Java.
Yes, Aspose.Cells allow you to write your data into csv format. Also you can output your data into number of other Ms-Excel formats like xls/xlsx/xlsm etc.
Please refer to this document for your reference
Please also see the code below that writes two strings in cell A1 and B1 and then save the workbook in csv format.
I have also attached the output csv file for you to view.
Please download and use the latest version:
Aspose.Cells for Java 7.1.1
Java
Workbook workbook = new Workbook();
Worksheet sheet = workbook.getWorksheets().get(0);
Cell cell = sheet.getCells().get(“A1”);
cell.putValue(“Hello Aspose!”);
cell = sheet.getCells().get(“B1”);
cell.putValue(“Hi Aspose”);
workbook.save(“F:\Output.csv”, SaveFormat.CSV);
I do not want to create a workbook and save it as a file. I want to write a java pojo in to csv format. For e.g.,
public class Person {
String name;
String address;
}
Say you instantiate this object
Person person = new Person (“My name”, “My address”);
I am looking for an API to write this object as csv:
My Name, My address and write this to output stream.
Hi,
For this requirement, please use our latest fix with Cells.ImportCustomObjects() method,.
Please see the following sample code.
Java
ArrayList al = …;
…;
cells.importCustomObjects(al, startRow, startColumn, null);
wb.save(outputStream, SaveFormat.CSV);