Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8696421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:16:09+00:00 2026-06-13T01:16:09+00:00

I’m working on a utility to convert excel file from one format to another.

  • 0

I’m working on a utility to convert excel file from one format to another. I was suggested to use jxl library to meet the requirements which are as follows.
read the file sheet by sheet and do following

get the sheet name, make it key of a map and then get its column headers and make them value.

it will result in following

   Map<String, List<String>> result = result<key=sheetName, value=list of column headers> 

Do this for all sheets in the given file

I did this in following way

public Map> function(String filePath ) throws IOException, BiffException{

       Map<String, List<String>> map = new HashMap<String, List<String>>(); 
    Workbook workBook=Workbook.getWorkbook(new File (filePath));
      String [] sheetNames = workBook.getSheetNames();
      Sheet sheet=null;
      List<String > fields = new ArrayList<String>();
      for (int sheetNumber =0; sheetNumber < sheetNames.length; sheetNumber++){
         sheet=workBook.getSheet(sheetNames[sheetNumber]);
         for (int columns=0;columns < sheet.getColumns();columns++){
             fields.add(sheet.getCell(columns, 0).getContents());


         }
         map.put(sheetNames[sheetNumber],fields);

      }
      return map;
}

I did this with a hope of getting desired result but what it does is that it stores column headers of all sheets against each key as value.
i.e. if there are two sheets in file named as

  1. sheet1
  2. sheet2

and following are their column headers

Sheet1 -> id, name
sheet2 -> category, price

then map will be like

result<sheet1,<id, name, caegory, price>>
result<sheet2,<id, name, caegory, price>>

Can’t figure out what I’m doing wrong?
Help please, as my project has a lot of backend calculations and I don’t want to spend a lot of time in this thing.

Any help will be highly appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:16:09+00:00Added an answer on June 13, 2026 at 1:16 am

    I solved the issue after posting it here, but forgot to give solution here.
    The problem in above code is location of list declaration.
    It should be declared inside the for, so that it gets refreshed (emptied) after each iteration of loop and stores data of only one sheet at a time.
    The correct code is below.

          Map<String, List<String>> map = new HashMap<String, List<String>>(); 
          Workbook workBook=Workbook.getWorkbook(new File (filePath));
          String [] sheetNames = workBook.getSheetNames();
          Sheet sheet=null;
          for (int sheetNumber =0; sheetNumber < sheetNames.length; sheetNumber++){
             List<String > fields = new ArrayList<String>();
             sheet=workBook.getSheet(sheetNames[sheetNumber]);
             for (int columns=0;columns < sheet.getColumns();columns++){
                 fields.add(sheet.getCell(columns, 0).getContents());                 
             }
             map.put(sheetNames[sheetNumber],fields); 
          }
          return map;
    }
    

    Hope It’ll help someone

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.