About the Java read to Excel

Source: Internet
Author: User

/*
Note: Read the Excel file Save as 2003 version of Excel, otherwise you may get an error
Don't forget to import third-party jar packages
*/

Package Com.zzp.ExcelParse;



Import JXL. Cell;
Import JXL. Sheet;
Import JXL. Workbook;
Import Jxl.read.biff.BiffException;

Import Java.io.File;
Import Java.io.IOException;


/**
* Read the Excel table
* Created by Hasee on 2016/11/29.
*/
public class Obtainexceldata {
Private WorkbookWorkbook =Null
Private SheetSheet =Null

/*
@see: Loading files
@parma:p ath File path
@return: Whether the execution was successful
*/
public BooleanGetFile (String path) {
if (path.length () = =0 | | Path = =NULL) {
return false;
}
try {
Workbook = workbook.Getworkbook (New File (PATH);
return true;
}catch (IOException e) {
E.printstacktrace ();
}catch (Biffexception e) {
E.printstacktrace ();
}
return false;
}

/*
@see: The table is obtained according to the table subscript
@parma: Subscript Sheetindex the underlying
@return: Whether the execution was successful
*/
public BooleanGetsheet (int Sheetindex) {
if (Sheetindex >=0) {
Sheet =Workbook.getsheet (Sheetindex);
return true;
}
return false;
}

/*
@see: Get table by table name
@parma: SheetName table name
@return: Whether the execution was successful
*/
public BooleanGetsheet (String sheetname) {
if (Sheetname.length () >0 | | SheetName! =NULL) {
Sheet =Workbook.getsheet (SheetName);
return true;
}
return false;
}

/*
@see: Reading data by column (without reading headers)
@parma: rowindex The number of columns queried
@parma: Rows in row Excel table
@parma: RowData stores a list of data retrieved
@return: Get to a column of data
*/
Public string[]Getcol (int Colindex) {
if (Colindex <0) {
return null;
}
int row =Sheet.getrows ();
string[] RowData =New String[row];
Cell cell =Null
for (int i =1; I < row; i++) {
Cell =Sheet.getcell (ColindexI;
String Strrow = cell.getcontents ();
Rowdata[i-1] = Strrow;
}
Return RowData;
}

/*
@see: Reading data by rows
@parma: Number of rows queried by RowIndex
@parma: Col eccel column number of tables
@parma: RowData Stores the fetched row of data
@return: Gets the row of data
*/
Public string[]GetRow (int RowIndex) {
if (RowIndex <0)return null;
int col =Sheet.getcolumns ();
string[] RowData = new string[col];
cell cell = null;
for (int i = 0; I < Col cell = sheet.getcell (I, RowIndex) String Strrow = cell.getcontents () Rowdata[i] = Strrow "
return rowdata;
}
}
/span>

About Java reading to Excel

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.