RE: How to read and write excel sheet using java in Linux environment?

please provide me example..

waiting forĀ  u r reply..

Add Comment
2 Answers

For Reading Excel File :

import java.io.File;

import java.io.FileInputStream;

import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

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 ReadExcelFile

{
public Sheet readExcel(String filePath, String fileName, String sheetName) throws IOException

{

File file = new File(filePath+"//"+fileName);

FileInputStream inputStream = new FileInputStream(file);

Workbook Workbook1 = null;

String fileExtensionName = fileName.substring(fileName.indexOf("."));
if(fileExtensionName.equals(".xlsx"))

{

Workbook1 = new XSSFWorkbook(inputStream);

}

else if(fileExtensionName.equals("xls"))

{

Workbook1 = new HSSFWorkbook(inputStream);

}
Sheet sheet1 = Workbook1.getSheet(sheetName);

return sheet1;
}
}
Train Answered on October 18, 2014.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.