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.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.