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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:34:00+00:00 2026-06-02T04:34:00+00:00

I am trying to add a comment to a cell in Excel. I am

  • 0

I am trying to add a comment to a cell in Excel. I am using jxl library to do that:

   cell = sheet.getWritableCell(1, 2); // cols, rows
   WritableCellFeatures wcf = cell.getWritableCellFeatures();
   wcf.setComment("comment2");

The last line returns: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException. Despite many attempts I can’t fix it. Help will be appreciated. Thank you.

–EDIT–
This is the addNumber method after modifications:

private static void addNumber(WritableSheet sheet, int column, int row,
        double d) throws WriteException, RowsExceededException {

    Number number;
    number = new Number(column, row, d, timesStandard);

    //sheet.addCell(number); // need to add the cell first

    if (user wants to add a comment) {
        WritableCellFeatures wcf = new WritableCellFeatures();
        wcf.setComment("the comment");
        number.setCellFeatures(wcf);
    }

    //sheet.addCell(number); // but may need to add the cell with comments as well
}
  • 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-02T04:34:02+00:00Added an answer on June 2, 2026 at 4:34 am

    Have you previously added a cell at that location? The problem is that you can’t set cell features on an EmptyCell and it will always return null as its cell features.

    If you add a cell first, it works (try/catch omitted for clarity), as shown by the code below. Note that it also sets a WritableCellFeatures on the new Label cell first, since initially, cell features are always null.

                WritableWorkbook book = Workbook.createWorkbook(new File("output.xls"));
                WritableSheet sheet = book.createSheet("Some Sheet", 0);
    
                Label label = new Label(1, 2, "Some label"); 
                sheet.addCell(label); // add cell!
    
                WritableCellFeatures wcf = new WritableCellFeatures();
                wcf.setComment("Hello!");
    
                // set cell features!
                label.setCellFeatures(wcf);
    
                book.write();
                book.close();
    

    Using this with the method in the OP:

    I modified the method to return the created (and added!) Number instance. If you don’t want that, you could instead retrieve the same cell using WritableWorkbook.getWritableCell() using the same row/col.

    public static void main(String[] args) throws IOException, RowsExceededException, WriteException {
    
        File file = new File("output.xls");
        WritableWorkbook workbook = Workbook.createWorkbook(file);
        WritableSheet sheet = workbook.createSheet("First Sheet", 0);
    
        Number number = addNumber(sheet, 3, 2, 565d);
    
        WritableCellFeatures wcf = number.getWritableCellFeatures();
        if (wcf == null) wcf = new WritableCellFeatures();
        wcf.setComment("the comment");
        number.setCellFeatures(wcf);
    
        workbook.write(); 
        workbook.close();
    
    }
    
    private static Number addNumber(WritableSheet sheet, int column, int row,
            double d) throws WriteException, RowsExceededException {
    
        Number number = new Number(column, row, d, timesStandard);
        sheet.addCell(number); // need to add the cell first
        return number;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying add a tab to my web page that looks like this: Using
I'm trying to add comments to cells in an Excel 2007 spreadsheet. I'm using
i am trying to do a simple form that adds a new comment using
I'm trying to add comments to a Post model class Comment < ActiveRecord::Base belongs_to
trying to add an ExpiresDefault ExpiresByType to content on my website so that way
Trying to add a class object into a List using reflection, but when invoking
I'm trying to add comment in php line. But I don't know if a
I'm trying to allow comments by anon users but the add comment form, add
I'm trying to add a .css file that targets Windows Mobile, and as media=handheld
I'm trying to add a form to allow users to comment on posts on

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.