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

Source: Internet
Author: User

Objective

Report output is often involved in Java application development, while general reports often lack generality, which makes it inconvenient for users to personalize editing. Because of its cross-platform features, Java programs cannot manipulate Excel directly. Therefore, this article explores the POI line of Sight Java program for the number of columns and rows in Excel reading.

Methods are as follows

Gets the specified row, with the index starting at 0
Hssfrow=hssfsheet.getrow (1);
Gets the specified column, with the index starting at 0
Hssfcell=hssfrow.getcell ((short) 6);

Gets the total number of
//int rownum=hssfsheet.getlastrownum ();
Gets the total number of records in an Excel 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); Get a third workbook (2008 workbook)
//Fill the above table, the data needs to be queried from the database
hssfrow row5 = Sheet.getrow (4);//Get the fifth line of the workbook
Hssfcell cell54 = Row5.getcell (3);//Get Fourth cell
cell54.setcellvalue ("Test taxpayer name") on line fifth;//Assign value to cell
//Get total number of columns
int coloumnum= Sheet.getrow (0). Getphysicalnumberofcells ();
int Rownum=sheet.getlastrownum ();//Get total number of rows

Summarize

The above is the entire content of this article, I hope the content of this article for everyone to learn or use Java can bring some help, if you have questions you can message exchange.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.