Get CSV file Column count in java

Hi Team,

Could you please guide me on how to get column count from CSV file using Aspose 8.0.1 with Java 6.

Thanks,

GUM

Hi Gum,


Thank you for contacting Aspose support.

Please try the below provided code snippet on your end to get the number of columns in a CSV.

Java

Workbook book = new Workbook(myDir + “Input.csv”);
Worksheet sheet = book.getWorksheets().get(0);
Cells cells = sheet.getCells();

//For total number of data columns, please add 1 to the MaxDataColumn value
//because columns have zero based index therefore when MaxDataColumn value is 1
//that means there are total 2 data columns in the worksheet/CSV
System.out.println((cells.getMaxDataColumn() + 1));

Please feel free to write back in case you need our further assistance.