Parsing the Java Code Toolbox Excel

Source: Internet
Author: User

1. Using Open Source Tools Jxl.jar

2. Function: Parse general Excel. The XLS format test is feasible and xlsx is not tested. The Excel Test format is a simple layout file like table. The first behavior title, followed by the behavior content. Code

Content is parsed correctly and the first row (header) is automatically discarded.

3. Sample code (import the necessary libraries yourself)

1   Public Static voidReadexcel ()throwsbiffexception, ioexception{2    //Create a list to store the read content3List List =NewArrayList ();4Workbook RWB =NULL;5Cell cell =NULL;6     7     //Create an input stream8InputStream stream =NewFileInputStream ("D:\\testjxl.xls");9     Ten     //get the Excel file object OneRWB =Workbook.getworkbook (stream); A      -     //gets the default first for the specified worksheet of a file -Sheet Sheet = Rwb.getsheet (0);  the     -     //Number of Rows (table header directory not required, starting from 1) -      for(inti=0; I<sheet.getrows (); i++){ -       +      //create an array to store the values for each column -string[] str =Newstring[sheet.getcolumns ()]; +       A      //Number of columns at       for(intj=0; J<sheet.getcolumns (); J + +){ -       -       //get the value of row i, column J -Cell =Sheet.getcell (j,i);  -STR[J] =cell.getcontents (); -        in      } -      //Save the newly acquired column to list to List.add (str); +     } -      for(intI=0;i<list.size (); i++){ thestring[] str =(string[]) list.get (i); *       for(intj=0;j<str.length;j++){ $ System.out.println (Str[j]);Panax Notoginseng      } -     } the}

Parsing the Java Code Toolbox Excel

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.