Handling Excel Files

Java Input & Output Operations, Handling Flat Files, Handling Excel Files and handling Database Files. Read Input, Write output on the console, Read Files, Write Files, Compare Data and Manipulate File Data.
Post Reply
Gowtham Ramesh
Posts: 66
Joined: Thu Nov 22, 2018 5:23 am

Handling Excel Files

Post by Gowtham Ramesh » Tue Nov 27, 2018 11:29 am

How to handle Excel File (Read and Write) in Java Programming?

Posts: 76
Joined: Thu Jan 03, 2019 3:58 am

Re: Handling Excel Files

Post by srini » Mon Jan 07, 2019 9:27 am

Excel is a very popular file format created by Microsoft. Although it is not an opened file format, Java applications can still read and write Excel files using the Apache POI - the Java API for Microsoft Documents, because the development team uses reverse-engineering to understand the Excel file format. Hence the name POI stands for Poor Obfuscation Implementation.

public class ReadandWriteExcel {

 public static void main(String []args){

  try {

  // Specify the file path which you want to create or write

  File src=new File("./testdata/test.xlsx");

  // Load the file

  FileInputStream fis=new FileInputStream(src);

   // load the workbook

   XSSFWorkbook wb=new XSSFWorkbook(fis);

  // get the sheet which you want to modify or create

   XSSFSheet sh1= wb.getSheetAt(0);

 // getRow specify which row we want to read and getCell which column







// here createCell will create column

// and setCellvalue will set the value




// here we need to specify where you want to save file

 FileOutputStream fout=new FileOutputStream(new File("location of file/filename.xlsx"));

// finally write content 


// close the file


  } catch (Exception e) {





Post Reply

Return to “Java IO & File Handling”