JAVA Code to Create an Excel File in Relative Path

Using excel files is one of the most common method for test data and other types of data management. The java code to create an Excel file is very easy and most of the code is self explanatory. Lets have a look at the same:
 
Eclipse needs to be pointed to the required JAR files in order to make it work with various functions provided by apache. Read more on Apache at it’s official website: Apache POI

 

The poi(s) need to be added to the project before running this code. Different versions may or may not support all functions and need to be worked with accordingly. Below is the snapshot of POI(s) used in my program. They can be downloaded from https://poi.apache.org/download.html#archive

Eclipse - Java Build Path
Eclipse-Java Build Path

 

Below is the JAVA class which creates an excel file in the “Relative Path”.

The code first checks for the directory “temp” at the relative path and creates if it does not exists.

Next, the excel file with three columns namely – “First Name”, “Last Name” and “Country”. If the file already exists, the code overwrites the same.

The code prints following on console when run the first time:
Directory already exists!
relativePath:tempMyExcelFile.xlsx
Excel File created: C:FunctionalTestAutomationproject_TestProject1tempMyExcelFile.xlsx
When we run the code second time, the console is as below:
Directory already exists!
relativePath:tempMyExcelFile.xlsx
Excel File created: C:FunctionalTestAutomationproject_TestProject1tempMyExcelFile.xlsx

Tada! That was one of the ways to write JAVA code and create an Excel file at the relative path. Hope it helped.

83 thoughts on “JAVA Code to Create an Excel File in Relative Path”

  1. I like your post there is a lot of information about software testing, which i would like to learn, thank you for the great guide. Very useful post and I think it is rather easy to see from the other comments as well that this post is well written and useful.Keep up the good work.. Read more about QA Services

    Reply
  2. Hmm it looks like your site ate my first comment (it was super long) so I
    guess I’ll just sum it up what I submitted and say, I’m thoroughly enjoying your blog.
    I too am an aspiring blog writer but I’m still new
    to everything. Do you have any helpful hints for newbie blog writers?
    I’d definitely appreciate it.

    Reply
  3. Do you mind if I quote a few of your posts as long as I provide credit and sources back to your blog?

    My blog site is in the exact same area of interest as yours and my users would
    truly benefit from a lot of the information you present here.
    Please let me know if this okay with you. Thank you!

    my page … CBD for dogs

    Reply
  4. Hi there! This article could not be written any better!

    Looking through this article reminds me of my previous roommate!
    He always kept preaching about this. I am going to forward this article to him.

    Pretty sure he’s going to have a great read. Many thanks for sharing!

    Reply
  5. Amazing! This blog looks exactly like my old one! It’s
    on a completely different subject but it has pretty much the same layout and design. Superb choice of colors!

    Feel free to visit my homepage … delta 8

    Reply
  6. I am not certain where you’re getting your information, however good topic.

    I needs to spend a while finding out much more or working out more.
    Thank you for fantastic info I was on the
    lookout for this info for my mission.

    my web page … delta 8 thc

    Reply
  7. Very nice post. I just stumbled upon your weblog and wanted to say that I have
    truly enjoyed browsing your blog posts. In any case
    I’ll be subscribing to your rss feed and I hope you write again very soon!

    Feel free to surf to my page … delta 8

    Reply
  8. I got this web page from my pal who told me about this website and at
    the moment this time I am visiting this website and reading very informative content at this time.

    Feel free to visit my web-site cbd

    Reply
  9. Greetings from Ohio! I’m bored to tears at work so I decided to browse your site on my
    iphone during lunch break. I really like the info you provide here and can’t wait to take a look
    when I get home. I’m amazed at how fast your blog loaded on my cell phone
    .. I’m not even using WIFI, just 3G .. Anyways, wonderful site!

    my web blog – best delta 8 thc carts

    Reply
  10. Wonderful goods from you, man. I have understand your stuff previous to and you are just extremely
    great. I really like what you’ve acquired here, certainly like what you’re stating and the way in which you
    say it. You make it enjoyable and you still care for to keep it smart.

    I cant wait to read far more from you. This is really a tremendous site.

    My blog post :: delta 8 thc store

    Reply
  11. Your style is very unique compared to other people
    I have read stuff from. I appreciate you for posting when you have the opportunity,
    Guess I will just book mark this blog.

    my web site: cbd

    Reply
  12. This design is incredible! You most certainly know how to keep a reader amused.
    Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Fantastic job.
    I really enjoyed what you had to say, and more than that, how you presented
    it. Too cool!

    Reply
  13. I’m truly enjoying the design and layout of your site.
    It’s a very easy on the eyes which makes it much more
    enjoyable for me to come here and visit more often. Did you hire out a
    designer to create your theme? Outstanding work!

    Feel free to visit my web blog – best delta 8 carts

    Reply
  14. I think this is one of the most important info for me. And i’m glad reading your article.
    But wanna remark on few general things, The site style is perfect,
    the articles is really great : D. Good job, cheers

    my web page – slot

    Reply
  15. Hey there! I could have sworn I’ve been to this website before but after checking through some of the post I realized it’s new to me.
    Anyhow, I’m definitely delighted I found it and I’ll be bookmarking and checking back often!

    Feel free to visit my web-site :: slot online

    Reply
  16. I might want to thank you for the endeavors you have placed in writing this site. I’m expecting to look at a similar high-grade content from you later on too. Truth be told, your experimental writing capacities has urged me to get my own personal site now 😉

    Reply
  17. Howdy just wanted to give you a brief heads up and let you know a few of
    the pictures aren’t loading properly. I’m not sure
    why but I think its a linking issue. I’ve tried it in two
    different internet browsers and both show the same results.

    Also visit my web-site: US Magazine

    Reply

Leave a Comment