That is more a stackoverflow question then a Mendix related question. See answer here: https://stackoverflow.com/questions/18489817/get-number-of-columns-of-a-particular-row-in-given-excel-using-java
You need to do this in Java.
Regards,
Ronald