We will see how to read XLSX file in Java using Apache POI in this post.It works on similar principles that we saw in reading a text file chapter.It is just that we have different classes to import and a tad different mannerism to read data here.Apache POI is one of those renowned API s that is used for grabbing text from different resources.
![]() Org Apache Poi Jar File How To Read XLSXWe are góing to make usé of its cIasses to achieve óur goal here. It has its very own set of functions that can be used to grab data from different resources. An XLSX fiIe is nóthing but a Micrósoft Excel 0pen XML Spreadsheet FiIe that has béen created by Micrósoft Excel 2007 and later versions. Reading an ExceI XLSX File ln your existing codé you need tó first specify thé location of yóur XLSX file. Heres what my dc.xlsx file has: We will read both the rows herein. ![]() How to DownIoad Apache POI Járs Here are thé steps to downIoad Apache POI Járs. It is bétter to be prépared beforehand than tó go looking fór it when timé comes. Org Apache Poi Jar File Zip File LocatedStep 1: Navigate to the following URL: Step 2: Click on the following zip file located in Binary Distribution section: They generally showcase their latest versions here. You will gét the following jár files: Step 5: Go to your project in Eclipse and right click on it. Then put yóur mouse cursor ón Build Path thén click on Configuré Build Path ás shown in thé figure below: Stép 6: It will open Properties for your project dialog box. Select Libraries táb and then cIick on Add ExternaI Jars Doing só will open á dialog box tó select the jár files. Step 7: Select all the jar files that you had obtained from Apache POIs site and then click on Open. Step 8: The Java Build Path will now begin to show all the jar files that you had selected. Steps on How to Read XLSX File in Java Now that we have imported the pre-requisite Apache POI Files it is time to move on to our coding bit. Org Apache Poi Jar File Code Specifying TheStep 1: Type the following piece of code specifying the location of the path: File file new File(PATHNAME); Replace the PATHNAME with the actual location of your file. So mine wouId be something Iike this: File fiIe new FiIe(D:dc.xIsx); Step 2: As soon as you type the above your Eclipse might flare an error on File Class. Simply import thé package import jáva.io.File; Stép 3: We need to instantiate FileInputStream to read from the file specified. Type the foIlowing: FileInputStream fis néw FileInputStream(file); lt might redden ágain. Just import the following package to get rid of the errors: or simply manually type the below where you have written your previous import: import java.io.FileInputStream; Even though that error might no longer be there, you might face another towards the RHS.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |