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 at 0 hssfRow=hssfSheet.getRow(1);//Get the specified column, the index starts at 0 hssfCell=hssfRow.getCell((short)6);//Get the total number of rows//int rowNum=hssfSheet.getLastRowNum();//Get the total number of records in an excel table int rowNum=storagesList.size();//Get 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); // Get the third workbook (2008 workbook)// Populate the above table, and the data needs to be queryed from the database. HSSFRow row5 = sheet.getRow(4); // Get the fifth line of the workbook HSSFCell cell54 = row5.getCell(3); // Get the fourth cell of the fifth line cell54.setCellValue("test taxpayer name"); // 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 rowsSummarize
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.