Earlier in this post, we introduced Apache POI- a Java API useful for interacting with Microsoft office documents.
Now we’ll see how can we read and write to an excel file using the API.
Writing an excel file
Writing a file using POI is very simple and involve following steps:
- Create a workbook
- Create a sheet in workbook
- Create a row in sheet
- Add cells in sheet
- Repeat step 3 and 4 to write more data
Reading an excel file
Reading an excel file is also very simple if we divide this in steps.
- Create workbook instance from excel sheet
- Get to the desired sheet
- Increment row number
- iterate over all cells in a row
- repeat step 3 and 4 until all data is read
Sometimes you need to read a file at different location: Here’s how you can do it:
You can append to the existing file using following code:
This article is contributed by Pankaj Kumar. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Creating Sheets in Excel File in Java using Apache POI
- Creating a Cell at specific position in Excel file using Java
- Reading a CSV file in Java using OpenCSV
- Difference Between Apache Hive and Apache Impala
- Difference Between Apache Hadoop and Apache Storm
- Difference between Apache Tomcat server and Apache web server
- How to Convert Data URI to File then append to FormData?
- How to create a dynamic JSON file by fetching data from localserver database ?
- Apache POI | Getting Started
- Apache POI | Introduction
- Why Apache Kafka is so Fast?
- Introduction to Apache CouchDB
- Introduction to Apache Cassandra
- How to get file input by selected file name without path using jQuery ?
- Apache Cassandra (NOSQL database)
- Difference Between Hadoop and Apache Spark
- How to Install and Run Apache Kafka on Windows?
- How to install Apache server in Ubuntu ?
- Difference Between CSV and Excel