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

  • Home
  • SEARCH
  • 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 7765061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:04:49+00:00 2026-06-01T15:04:49+00:00

i managed to write the data to a single column. My req is to

  • 0

i managed to write the data to a single column.
My req is to write the data to the next adjacent column without overriding the data in the fist column.
Any help?

InputStream inp;
    try {
        inp = new FileInputStream("D:\\test.xls");
        Workbook wb = WorkbookFactory.create(inp);
        Sheet sheet = wb.getSheetAt(0);
        Row row =  null;

        Cell c = null;

        int rowNum=0;
        Set<String> keySet = new HashSet<String>();
        keySet = tushMap.keySet();
        for (Entry<String, String> entry : tushMap.entrySet()) {
            row=sheet.createRow((short) (sheet.getLastRowNum() + 1));
            System.out.println((short) (sheet.getLastRowNum() + 1));
            c = row.createCell(0);
            c.setCellValue("fff");
            System.out.println("fff");
            System.out.println(entry.getKey() + "/" + entry.getValue());
            rowNum++;
        }


        FileOutputStream fileOut = new FileOutputStream("D:\\test.xls");
        wb.write(fileOut);
        fileOut.close();

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (InvalidFormatException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

This is the code written to populate the 1st column.
Populating the second column overrides the fist 1..
Pls suggest some solution..
Thanks in advance.

  • 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-01T15:04:50+00:00Added an answer on June 1, 2026 at 3:04 pm

    To get the data side by side get the last row outside the loop and save it as the begening row. Keep a counter for which row you are editing inside the loop. If the row is null create the row.

    rowPos = sheet.getLastRowNum();
    for (Entry<String, String> entry : tushMap.entrySet()) {
        rowPos++;
        Row currentRow = sheet.getRow(rowPos);
        if(null == currentRow)
            currentRow = createRow(rowPos);
    

    EDIT:

    I am getting the desierd output using this

    int beginingRow = sheet.getLastRowNum();
                for( int col=0; col<2; col++){
                    int currentRow = beginingRow;
                    for (int i=0; i<10; i++) {
                        currentRow++;
                        row = sheet.getRow(currentRow);
                        if(null == row)
                            row=sheet.createRow(currentRow);
                        c = row.createCell(col);
                        c.setCellValue("fff");
                        System.out.println("fff");
                        //System.out.println(entry.getKey() + "/" + entry.getValue());
                        rowNum++;
                    }
                }
    

    Output

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

Sidebar

Related Questions

I managed to write add program that upon the user click a button, he
So far I have managed to write some code that should print the source
I'm trying to write a managed library in C# that will act as an
Can .NET (managed code) read and write to CouchDB? I would like to build
I trying to write a simple function to call unmanaged code from managed code.
What are cons to write and manage CSS in notepad? in compare to any
I have make a little Extension for Magento 1.6.2. I managed to write code
When we developers write data access code what should we really worry about if
I managed to write a for loop to compare letters in the following vector:
I am just wandering is there is any reference how to design DAO (data

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.