Get the App
SLTechnology News&Howtos  ›  Development  › 

How does java operate the excel table

Shulou Source: shulou.com Published: 2022-06-02 08:43:48 10月03日 Update

In this issue, the editor will bring you about how java operates the excel table. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Package excel

Import java.io.File

Import java.io.FileInputStream

Import java.io.InputStream; import jxl.Cell

Import jxl.CellType

Import jxl.Sheet

Import jxl.Workbook

Public class ReadExcel

{

Public void readExcel ()

{

Try {

/ / build Workbook object, read-only Workbook object

/ / create Workbook directly from local file / / create Workbook from input stream

File file = new File ("E:/temp/HodeOA_2005/Book1.xls")

InputStream is = new FileInputStream (file)

Workbook rwb = Workbook.getWorkbook (is)

/ / get the number of worksheets (Sheet) in workbook (Workbook)

/ / int sheets = rwb.getNumberOfSheets ()

/ / returns an array of Sheet objects in the workbook (Workbook)

Sheet [] sheets = rwb.getSheets ()

For (int I = 0; I

{

System.out.println ("-")

System.out.println ("[information for worksheet Sheet" + I + "]")

/ / get the name of the worksheet (Sheet)

String sheetName = sheets [I] .getName ()

System.out.println ("Sheet name:" + sheetName)

/ / get the total number of columns contained in the Sheet table

Int rsColumns = sheets [I] .getColumns ()

System.out.println ("Total Sheet columns:" + rsColumns)

/ / get the total number of rows contained in the Sheet table

Int rsRows = sheets [I] .getRows ()

System.out.println ("Total rows of Sheet:" + rsRows)

/ / output cell information line by line

System.out.println ("Sheet content:" + rsRows)

For (int j = 0; j {

System.out.print ("Line" + j + ":")

/ / gets all the cells in a row, and returns an array of cell objects, as shown in the example:

Cell [] cell = sheets[ I] .getRow (j)

For (int k = 0; k {

/ / get the unit content

String cellContent = cell [k] .getContents ()

/ / get the unit type

CellType cellType= cell [k] .getType ()

System.out.print ("" + cellContent+ "[" + cellType+ "]")

}

System.out.println ()

}

}

Rwb.close ()

}

Catch (Exception e)

{

E.printStackTrace ()

}

}

Public static void main (String [] args)

{

ReadExcel re = new ReadExcel ()

Re.readExcel ()

}

}

[@ more@] package excel

Import java.io.File

Import java.io.FileInputStream

Import java.io.InputStream; import jxl.Cell

Import jxl.CellType

Import jxl.Sheet

Import jxl.Workbook

Public class ReadExcel

{

Public void readExcel ()

{

Try {

/ / build Workbook object, read-only Workbook object

/ / create Workbook directly from local file / / create Workbook from input stream

File file = new File ("E:/temp/HodeOA_2005/Book1.xls")

InputStream is = new FileInputStream (file)

Workbook rwb = Workbook.getWorkbook (is)

/ / get the number of worksheets (Sheet) in workbook (Workbook)

/ / int sheets = rwb.getNumberOfSheets ()

/ / returns an array of Sheet objects in the workbook (Workbook)

Sheet [] sheets = rwb.getSheets ()

For (int I = 0; I {

System.out.println ("-")

System.out.println ("[information for worksheet Sheet" + I + "]")

/ / get the name of the worksheet (Sheet)

String sheetName = sheets [I] .getName ()

System.out.println ("Sheet name:" + sheetName)

/ / get the total number of columns contained in the Sheet table

Int rsColumns = sheets [I] .getColumns ()

System.out.println ("Total Sheet columns:" + rsColumns)

/ / get the total number of rows contained in the Sheet table

Int rsRows = sheets [I] .getRows ()

System.out.println ("Total rows of Sheet:" + rsRows)

/ / output cell information line by line

System.out.println ("Sheet content:" + rsRows)

For (int j = 0; j {

System.out.print ("Line" + j + ":")

/ / gets all the cells in a row, and returns an array of cell objects, as shown in the example:

Cell [] cell = sheets[ I] .getRow (j)

For (int k = 0; k {

/ / get the unit content

String cellContent = cell [k] .getContents ()

/ / get the unit type

CellType cellType= cell [k] .getType ()

System.out.print ("" + cellContent+ "[" + cellType+ "]")

}

System.out.println ()

}

}

Rwb.close ()

}

Catch (Exception e)

{

E.printStackTrace ()

}

}

Public static void main (String [] args)

{

ReadExcel re = new ReadExcel ()

Re.readExcel ()

}

}

The above is the editor for you to share the java how to operate the excel table, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Tags: Unit object work content information name head line array middle worker line number example file type analysis input output professional small and medium rich in content Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information vpn NVidia Apple Linux