SoFunction
Updated on 2025-03-08

JAVA uses POI to get the number of columns and rows in Excel

Preface

Report output is a content that is often involved in Java application development, and general reports often lack universality and are not convenient for users to edit personalized. Due to its cross-platform features, Java programs cannot directly manipulate Excel. Therefore, this article discusses the POI line of sight Java program to read the number of columns and rows in Excel.

The method is as follows

//Get the specified row, the index starts from 0hssfRow=(1);
//Get the specified column, the index starts from 0hssfCell=((short)6);

//Get the total number of rows//int rowNum=();
//Get the total number of records in an excel tableint rowNum=();
//Get the total number of columnsint columnNum=();

FileInputStream inp = new FileInputStream("E:\\"); 
HSSFWorkbook wb = new HSSFWorkbook(inp);
HSSFSheet sheet = (2); // Obtain the third workbook (2008 workbook)// Populate the above table and the data needs to be queried from the databaseHSSFRow row5 = (4); // Get the fifth line of the workbookHSSFCell cell54 = (3);// Get the fourth cell of the fifth line("Testing the Taxpayer Name");// Assign values ​​to cells//Get the total number of columnsint coloumNum=(0).getPhysicalNumberOfCells();
int rowNum=();//Get the total number of rows

Summarize

The above is the entire content of this article. I hope that the content of this article will be of some help to everyone learning or using Java. If you have any questions, you can leave a message to communicate.