The number of table columns in the xls file is getting incorrect

Hi
This is my Code.

Workbook workbook = new Workbook(“c:/1.xls”);
WorksheetCollection wc = workbook.getWorksheets();
Worksheet worksheet = wc.get(0);
Cells cells = worksheet.getCells();
int maxColumnNum = cells.getMaxColumn();

The maxColumnNum is 4,but in the file , it is 5 ,why?

Th1.xls.zip (36.5 KB)
anks

@zhengkai,

Thanks for the template file and sample code.

I evaluated your scenario/ case a bit by using your template file and sample code. It is not an issue with the product and it works fine and as expected. Actually there are a few hidden sheets (e.g “初二” and “初四”) in your template file and when you use the line of code:
i.e.,

Worksheet worksheet = wc.get(0);

it will get the sheet “初二” at zero indexed position.

For your requirements, you should get the sheet by its name and not by its index, see the updated code segment which works fine as I tested:
e.g
Sample code:

Workbook workbook = new Workbook("f:\\files\\1.xls");
		WorksheetCollection wc = workbook.getWorksheets();
		Worksheet worksheet = wc.get("数学");
		Cells cells = worksheet.getCells();
		int maxColumnNum = cells.getMaxColumn();
		int maxDataColumnNum = cells.getMaxDataColumn();
		
		System.out.println(maxColumnNum);
		System.out.println(maxDataColumnNum);

Hope, this helps a bit.

Thank you very much

@zhengkai,

Good to know that your issue is sorted out by the suggested code segment. Feel free to write us back if you have further comments or questions, we will be happy to assist you soon.