Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does java operate the excel table

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report