Parse EXCEL usint Apache POI-HSSF and POI-XSSF

Categories: Java; Tagged with: ; @ July 27th, 2012 8:24

HSSF is the POI Project’s pure Java implementation of the Excel ’97(-2007) file format. XSSF is the POI Project’s pure Java implementation of the Excel 2007 OOXML (.xlsx) file format. HSSF and XSSF provides ways to read spreadsheets create, modify, read and write XLS spreadsheets.

 

package com.test;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class HSSFTest {
	public static void main(String[] args) {
		String xlsName = "D:/justForTest.xlsx";
		FileInputStream fis;
		try {
			fis = new FileInputStream(xlsName);
			Workbook workbook = new XSSFWorkbook(fis);
			
			// Get the first sheet;
			Sheet sheet = workbook.getSheetAt(0);
			
			// for each row
			for(Row row : sheet) {
				Cell cell = row.getCell(0); // get the cell
				// print cell contents.
				System.out.println(cell.getStringCellValue());
			}
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

<->



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.