Hi Team
I was trying to generate an excel workbook with the following code:
public static void main(String[] args) throws Exception{
FileInputStream fis = new FileInputStream(“templatelocation/HelloWorld.xls”);
Workbook workbook = new Workbook(fis);
WorksheetCollection worksheets = workbook.getWorksheets();
Worksheet worksheet = worksheets.get(0);
Cells cells = worksheet.getCells();
Cell cell;
cell = cells.get(“A1”);
cell.putValue(“Cell Value”);
cell = cells.get(“A2”);
cell.putValue(“Hello World”);
cell = cells.get(“A3”);
cell.setHtmlString(readString());
workbook.save(savelocation/test1.xls");
}
Please note that the readString() method returns a string like this:
test
I noticed that if the text that is set for the setHtmlString() happens to have style as in the text mentioned above, then aspose throws the following exception. Aspose cells seems to accept only style with DIV tags and not with any other tags. Is there a solution to this problem. We have data coming from various sources such as database, feeds which can contain any tags with style. The following is the exception thrown:
Exception in thread “main” java.lang.NullPointerException
at com.aspose.cells.b.a.o.a(Unknown Source)
at com.aspose.cells.aY.a(Unknown Source)
at com.aspose.cells.aY.a(Unknown Source)
at com.aspose.cells.aY.a(Unknown Source)
at com.aspose.cells.Cell.setHtmlString(Unknown Source)
at org.srini.aspose.cells.AsposeCellValueException.main(AsposeCellValueException.java:26)
In my case the data predominantly had span tags, the work around that I found was replacing span tags with div tags. But this is not a complete solution, there could be other HTML tags with style and that causes a problem.
I have attached the java file along with the template xls and the text file from which the program reads the string.
Thanks a lot. And have a great new Year!
Srini