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
- Apache POI | Introduction
- Apache POI | Getting Started
- Reading Data From Microsoft-Excel using Automation Anywhere
- Difference Between Apache Hadoop and Apache Storm
- Difference Between Apache Hive and Apache Impala
- Difference between Apache Tomcat server and Apache web server
- Creating a Cell at specific position in Excel file using Java
- Reading a CSV file in Java using OpenCSV
- How to Convert HTML Table into Excel Spreadsheet using jQuery ?
- Difference Between Hadoop and Apache Spark
- How to Install and Run Apache Kafka on Windows?
- Reading and Generating QR codes in Python using QRtools
- Difference Between CSV and Excel
- How to get file input by selected file name without path using jQuery ?
- Introduction to Apache Maven | A build automation tool for Java projects
- Introduction to Apache Cassandra
- Where does PHP store the error log? (php5, apache, fastcgi, cpanel)
- How to install Apache server in Ubuntu ?