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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:51:12+00:00 2026-06-17T10:51:12+00:00

I need to create multiple excel sheet in Java using jExcel API if one

  • 0

I need to create multiple excel sheet in Java using jExcel API if one sheet is full (65536 rows). Suppose if one sheet got full then in the next sheet it should start writing automatically from where it left off in the first sheet. I am just stuck on putting the logic to create it dynamically whenever one sheet is full. Below is the code that I have done so far.

public void write() throws IOException, WriteException {
    File file = new File(inputFile);
    WorkbookSettings wbSettings = new WorkbookSettings();

    wbSettings.setLocale(new Locale("en", "EN"));

    WritableWorkbook workbook = Workbook.createWorkbook(file, wbSettings);

    writingToExcel(workbook);
}


//Logic to create sheet dyanmically if one is full should be done here I guess?
private void writingToExcel(WritableWorkbook workbook) {

    workbook.createSheet("Report", 0);
    WritableSheet excelSheet = workbook.getSheet(0);
    try {
        createLabel(excelSheet);
        createContent(excelSheet);
    } catch (WriteException e) {
        e.printStackTrace();
    } finally {
        try {
            workbook.write();
            workbook.close();   
        } catch (IOException e) {
            e.printStackTrace();
        } catch (WriteException e) {
            e.printStackTrace();
        }

    }
}

private void createLabel(WritableSheet sheet) throws WriteException {

    WritableFont times10pt = new WritableFont(WritableFont.TIMES, 10);
    times = new WritableCellFormat(times10pt);
    times.setWrap(true);

    WritableFont times10ptBoldUnderline = new WritableFont(WritableFont.TIMES, 10, WritableFont.BOLD, false,UnderlineStyle.SINGLE);
    timesBoldUnderline = new WritableCellFormat(times10ptBoldUnderline);
    timesBoldUnderline.setWrap(true);

    CellView cv = new CellView();
    cv.setFormat(times);
    cv.setFormat(timesBoldUnderline);
    cv.setAutosize(true);

    // Write a few headers
    addCaption(sheet, 0, 0, "Header 1");
    addCaption(sheet, 1, 0, "This is another header");

}

private void createContent(WritableSheet sheet) throws WriteException,
        RowsExceededException {

    for (int i = 1; i < 70000; i++) {
        addNumber(sheet, 0, i, i + 10);
        addNumber(sheet, 1, i, i * i);
    }
}

private void addCaption(WritableSheet sheet, int column, int row, String s)
        throws RowsExceededException, WriteException {
    Label label;
    label = new Label(column, row, s, timesBoldUnderline);
    sheet.addCell(label);
}

private void addNumber(WritableSheet sheet, int column, int row,
        Integer integer) throws WriteException, RowsExceededException {
    Number number;
    number = new Number(column, row, integer, times);
    sheet.addCell(number);
}

I am not sure how to add that logic here in my code.

Any suggestions will be of great help?

Or in any case, can anyone provide me a simple example in which if one sheet is full, it should start writing automatically into different sheet (Second sheet)?

  • 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-17T10:51:14+00:00Added an answer on June 17, 2026 at 10:51 am

    I made changes to the following 2 methods:-

    private void writingToExcel(WritableWorkbook workbook) {
        try {
            // don't create a sheet now, instead, pass it in the workbook
            createContent(workbook);
        }
        catch (WriteException e) {
            e.printStackTrace();
        }
        finally {
            try {
                workbook.write();
                workbook.close();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            catch (WriteException e) {
                e.printStackTrace();
            }
    
        }
    }
    
    // instead of taking a sheet, take a workbook because we cannot ensure if the sheet can fit all the content at this point
    private void createContent(WritableWorkbook workbook) throws WriteException {
    
        int excelSheetIndex = 0;
        int rowIndex = 0;
        WritableSheet excelSheet = null;
    
        for (int i = 1; i < 70000; i++) {
    
            // if the sheet has hit the cap, then create a new sheet, new label row and reset the row count
            if (excelSheet == null || excelSheet.getRows() == 65536) {
                excelSheet = workbook.createSheet("Report " + excelSheetIndex, excelSheetIndex++);
                createLabel(excelSheet);
                rowIndex = 0;
            }
    
            // instead of using i for row, use rowIndex
            addNumber(excelSheet, 0, rowIndex, i + 10);
            addNumber(excelSheet, 1, rowIndex, i * i);
    
            // increment the sheet row
            rowIndex++;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create multiple Child Nodes in one element node in XML, do
Why do I need to create Multiple SSPs in MOSS? My manager (sharepoint administrator)
I'm new to GUI programming, but need to create a multiple window GUI. Does
I`v come across a need where I want to create multiple list items from
I need to create a WP site which will have multiple subjects. Each subject
I need to create an ASN.1 BER encoded file with multiple records. I've been
I need to setup multiple queues on an exchange. I would like to create
I need to create a script that extracts some data from a complex Excel
I need to know of a way to combine multiple SELECT statements in one
I need to create multiple statusbar notifications. When i pull down the statusbar, multiple

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.