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 8259407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:51:24+00:00 2026-06-08T02:51:24+00:00

Below program exports the data of the single table in excel file.My question is

  • 0

Below program exports the data of the single table in excel file.My question is if I have two tables then how to export its data in two different worksheets of the same excel file?

Suppose tab1 data in worksheet1 and tab2 data in worksheet2 of same excel sheet

public class CreateExcelFile{
        public static void main(String[]args){
    try{
    String filename="c:/data.xls" ;
    HSSFWorkbook hwb=new HSSFWorkbook();
    HSSFSheet sheet =  hwb.createSheet("new sheet");

    HSSFRow rowhead=   sheet.createRow((short)0);
    rowhead.createCell((short) 0).setCellValue("SNo");
    rowhead.createCell((short) 1).setCellValue("Name");
    rowhead.createCell((short) 2).setCellValue("Address");
    rowhead.createCell((short) 3).setCellValue("Contact No");
    rowhead.createCell((short) 4).setCellValue("E-mail");

    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:456/test", "root", "root");
    Statement st=con.createStatement();
    ResultSet rs=st.executeQuery("Select * from employee");
    int i=1;
    while(rs.next()){
    HSSFRow row=   sheet.createRow((short)i);
    row.createCell((short) 0).setCellValue(Integer.toString(rs.getInt("id")));
    row.createCell((short) 1).setCellValue(rs.getString("name"));
    row.createCell((short) 2).setCellValue(rs.getString("address"));
    row.createCell((short) 3).setCellValue(Integer.toString(rs.getInt("contactNo")));
    row.createCell((short) 4).setCellValue(rs.getString("email"));
    i++;
    }
    FileOutputStream fileOut =  new FileOutputStream(filename);
    hwb.write(fileOut);
    fileOut.close();
    System.out.println("Your excel file has been generated!");

    } catch ( Exception ex ) {
        System.out.println(ex);

    }
        }
    }
  • 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-08T02:51:25+00:00Added an answer on June 8, 2026 at 2:51 am

    Not sure if I get the question right, and I am also not a Java programmer, but here’s my theory which seems logical:

    HSSFWorkbook hwb=new HSSFWorkbook(); 
    HSSFSheet sheet =  hwb.createSheet("new sheet"); 
    

    Defines a new workbook / sheet object via the Java API provided (with “new sheet” being the name of the sheet).
    If you want to define a second sheet, then you should simply be able to:

    HSSFSheet sheet_2 =  hwb.createSheet("new_sheet_2"); 
    

    which creates and defines a new Sheet Object.
    Then when you:

    HSSFRow rowhead=   sheet.createRow((short)0);
    

    Obviously, you need to use the second sheet object you created, Sheet_2.
    The same applies to the rest of the code and when building the table.
    When writing to the file, I’m quite positive that you should get the result you expect.

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

Sidebar

Related Questions

I have a little confusion in the following two statements. The below program is
Below program contains two show() functions in parent and child classes, but first show()
I have the below program that will move files from one directory to other.
I have a Enumeration as shown in below program public class Test { public
The program below prints the following data: Wed,Jun,13,10:37:34,2012,759,41,0,30,10,0,0,1 Wed,Jun,13,10:38:34,2012,767,33,0,25,6,0,0,2 Wed,Jun,13,10:39:34,2012,758,42,0,32,10,0,0,0 Wed,Jun,13,10:40:35,2012,758,42,0,29,11,0,0,2 Wed,Jun,13,10:41:35,2012,761,39,0,34,5,0,0,0 Wed,Jun,13,10:42:35,2012,769,31,0,22,6,0,0,3 Wed,Jun,13,10:43:35,2012,754,46,0,29,17,0,0,0
Let say we have below program: class A { public: virtual fun(){}; }; class
In the below program , I intend to read each line in a file
Question: The below program throws a runtime error (invalid conversion from double) because there
I'm trying to export data from SPSS (Statistics program) to a local mysql database.
I have the below program in MEF Method 1: public ObjectResult<PartnerListingStatement> GetCommissionListingRecords(string uRL, PortalConstant.DataSourceType

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.