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

The second part of excel study notes

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

The second part of excel study notes

Import java.io.BufferedInputStream

Import java.io.File

Import java.io.FileInputStream

Import java.io.FileNotFoundException

Import java.io.IOException

Import java.text.DecimalFormat

Import java.text.SimpleDateFormat

Import java.util.ArrayList

Import java.util.Arrays

Import java.util.Date

Import java.util.List

Import org.apache.poi.hssf.usermodel.HSSFCell

Import org.apache.poi.hssf.usermodel.HSSFDateUtil

Import org.apache.poi.hssf.usermodel.HSSFRow

Import org.apache.poi.hssf.usermodel.HSSFSheet

Import org.apache.poi.hssf.usermodel.HSSFWorkbook

Import org.apache.poi.poifs.filesystem.POIFSFileSystem

Public class ExcelOperate {

Public static void main (String [] args) throws Exception {

/ / TODO Auto-generated method stub

File file = new File ("E:\\ data.xls")

String [] [] result = getData (file, 0)

Int rowLength = result.length

For (int I = 0 rowLength; I < rowLength; iTunes +)

{

For (int j = 0; j < result [I]. Length +)

{

System.out.println (result [I] [j] + "\ t")

}

/ / System.out.println ()

}

}

/ * *

* read the contents of Excel. The first dimension array stores the values of the grid columns in a row, and the two-dimensional array stores how many rows.

* @ param file reads the source Excel of the data

* @ param ignoreRows reads the number of rows ignored by the data. For example, the number of rows ignored without reading in the header is 1.

* @ return reads the contents of the data in the Excel

* @ throws FileNotFoundException

* @ throws IOException

, /

@ SuppressWarnings ("deprecation")

Private static String [] getData (File file, int ignoreRows) throws FileNotFoundException, IOException

{

List result = new ArrayList ()

Int rowSize = 0

BufferedInputStream in = new BufferedInputStream (new FileInputStream (file))

/ / Open HSSFWorkbook

POIFSFileSystem fs = new POIFSFileSystem (in)

HSSFWorkbook wb = new HSSFWorkbook (fs)

HSSFCell cell = null

For (int sheetIndex = 0 * * SheetIndex < wb.getNumberOfSheets (); sheetIndex++)

{

HSSFSheet st = wb.getSheetAt (sheetIndex)

/ / the first behavior title is not taken.

For (int rowIndex = ignoreRows; rowIndex rowSize)

{

RowSize = tempRowSize

}

String [] values = new String [rowSize]

Arrays.fill (values, "")

Boolean hasValue = false

For (short columnIndex = 0; columnIndex = 0bizimuri -)

{

If (str.charAt (I)! = 0x20)

{

Break

}

Length--

}

Return str.substring (0dint length)

}

}

Results:

43057

one

The first string

Y

0

N

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

Internet Technology

Wechat

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

12
Report