Le 18/10/2013 22:41, Florrie O. a écrit :


I'm processing a .ods spreadsheet with the jOpenDocument library. Since I
was processing strings, everything was ok, but when it comes to process
numbers it's a pain.

In my code I iterate the spreadsheet and make some computations based on
the value assumed by the cell at index x,y. Surprisingly enough, I can't
get the class of the values I get:

BigDecimal ferialestringa;
      while (true) {
                         boolean duplicate = false;
                         value = (String) sheet.getValueAt(0, count);
                         System.out.println(sheet.getValueAt(5, 
count).getClass());
                         ferialestringa = (BigDecimal) sheet.getValueAt(5, 
count);

This snippet prints out:

class java.math.BigDecimalclass java.lang.StringException in thread "main" 
java.lang.ClassCastException: java.lang.String cannot be cast to java.math.BigDecimal
     at InspectTwitter.main(InspectTwitter.java:78)

You can see that the value appears to belong to two different classes.

I see that during the first evaluation of the loop the cell at (5,count) contains a BigDecimal ; the second time the cell at (5,count) contains a String.

If I try to parse the returned object to a string, I get also another
ClassCastException:

class java.math.BigDecimalException in thread "main" 
java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.String
     at InspectTwitter.main(InspectTwitter.java:78)

Note that this time the class seems to be just BigDecimal.

This is coherent since the first time the loop has indeed a BigDecimal.

I tried to find documentation but only Sheet.getValueAt(String) is
available on this <http://www.jopendocument.org/docs/index.html> javadoc.
(I've found this method in tutorials though, and it seems to be working
very well on strings). What should I do?

From what I can tell, getValueAt() is working correctly ; you should verify your coordinates and the content of the cells (e.g. maybe the content of a cell looks like a number but is defined as string).


Cheers,
Sylvain

--

--- You received this message because you are subscribed to the Google Groups "jOpenDocument" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jopendocument+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to