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
- Reading Data From Microsoft-Excel using Automation Anywhere
- Creating a Cell at specific position in Excel file using Java
- Reading a CSV file in Java using OpenCSV
- Difference Between Apache Hadoop and Apache Storm
- Difference Between Apache Hive and Apache Impala
- 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 | Introduction
- Apache POI | Getting Started
- How to get file input by selected file name without path using jQuery ?
- Introduction to Apache CouchDB
- Introduction to Apache Cassandra
- Why Apache Kafka is so Fast?
- Excel VBA | sum() functions
- Difference Between CSV and Excel
- Apache Cassandra (NOSQL database)
- How to install Apache server in Ubuntu ?