JAVA USES POI to get the number of columns and rows for Excel

  • 2020-05-26 08:20:02
  • OfStack

preface

Report output is often involved in the application development of Java. However, one-like reports often lack universality and are not convenient for users to conduct personalized editing. The Java program cannot directly manipulate Excel due to its cross-platform nature. Therefore, this article explores how the POI line of sight Java program reads the number of columns and rows in Excel.

Methods the following


// Gets the specified row, the index from 0 start 
hssfRow=hssfSheet.getRow(1);
// Gets the specified column, index from 0 start 
hssfCell=hssfRow.getCell((short)6);

// Gets the total number of rows 
//int rowNum=hssfSheet.getLastRowNum();
// To obtain 1 a excel The total number of records in the table 
int rowNum=storagesList.size();
// Gets the total number of columns 
int columnNum=hssfRow.getPhysicalNumberOfCells();

FileInputStream inp = new FileInputStream("E:\\WEIAN.xls"); 
HSSFWorkbook wb = new HSSFWorkbook(inp);
HSSFSheet sheet = wb.getSheetAt(2); //  For the first 3 A work sheet (2008 The workbook )
//  Fill in the table above , The data needs to be queried from the database 
HSSFRow row5 = sheet.getRow(4); //  Get a copy of the workbook 5 line 
HSSFCell cell54 = row5.getCell(3);//  For the first 5 The first 4 A cell 
cell54.setCellValue(" Name of test taxpayer ");//  Assign a value to the cell 
// Get the total number of columns 
int coloumNum=sheet.getRow(0).getPhysicalNumberOfCells();
int rowNum=sheet.getLastRowNum();// Get the total number of rows 

conclusion

The above is the whole content of this article, I hope the content of this article can help you to learn or use Java, if you have any questions, you can leave a message to communicate.


Related articles: