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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:29:34+00:00 2026-06-01T14:29:34+00:00

Let me start by saying I’m very new to Java and to this site.

  • 0

Let me start by saying I’m very new to Java and to this site. I’ve read a book or two now and since then have been looking for small projects to keep myself entertained. I’ve tried to research this but I haven’t been able to find the information I need. With that said, this is my first question here so if this is very early beginner stuff and I’m missing something obvious I apologize.

Regarding the project, my brother-in-law has an issue at work where he has 90 or so Excel workbooks in a folder and he needs to merge the first worksheet of each report into one master workbook. He can do it manually but I thought it would be interesting to try and figure out a way to do it with Java.

I did some research and downloaded the JExcelAPI and added the .jar to my classpath. I’ve created two directories on my computer.

C:\Excel\

C:\Excel\Finished\

Inside C:\Excel\ I’ve created two dummy excel sheets. I’ve renamed the first sheet on each for testing purposes. In the finished folder I’ve created my master document that I intend to merge these sheets into. When the sheets are empty and I run this the sheets appear to get copied over. There are two sheets in the master file and their names correspond to the names I gave them in their respective workbooks so I assume this is working. However, when I add information to one of these sheets and try to run this I get a null pointer exception. I’ve been working on this for hours now so maybe I just need a break but I can’t figure out what’s wrong. I went to the website for JExcelAPI and tried what looks like an outdated method for doing this (before importSheet() existed). That didn’t work either and also returned a null pointer exception.

If someone has time and is familiar with JExcelAPI, could you let me know what’s wrong? I would really appreciate it. I’ve posted the error and my code below.

–Error–

spreadsheet1.xls
Exception in thread "main" java.lang.NullPointerException
at jxl.write.biff.SheetCopier.deepCopyCells(SheetCopier.java:996)
at jxl.write.biff.SheetCopier.importSheet(SheetCopier.java:542)
at jxl.write.biff.WritableSheetImpl.importSheet(WritableSheetImpl.java:2699)
at jxl.write.biff.WritableWorkbookImpl.importSheet(WritableWorkbookImpl.java:1897)
at sheetcopier.SheetCopier.main(SheetCopier.java:32)

–Code–

package sheetcopier;

import java.io.File;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.NotDirectoryException;
import java.nio.file.Path;
import java.nio.file.Paths;
import jxl.*;
import jxl.read.biff.BiffException;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;

public class SheetCopier {

public static void main(String[] args) throws WriteException, BiffException {
    Path inputpath = Paths.get("C:/Excel"); //Directory with excel documents to be copied
    File outputfile = new File("C:/ExcelFinished/finishedbook.xls"); //Master/End file

    //Read all files from directory
    try (DirectoryStream<Path> inputfiles = Files.newDirectoryStream(inputpath)){

        //Get a writable workbook
        WritableWorkbook writableworkbook = Workbook.createWorkbook(outputfile);            

        for(Path path: inputfiles)
        {
            Workbook sourceworkbook = Workbook.getWorkbook(path.toFile()); //Get the source workbook
            System.out.println(path.getFileName()); //Print workbook being processed
            Sheet readablesheet = sourceworkbook.getSheet(0); //Get the first sheet
            writableworkbook.importSheet(readablesheet.getName(), 0, readablesheet); //Import the sheet into the new workbook
            //Sheet names are imported if sheets are empty.  If sheets are populated I get a null pointer error.
        }

        writableworkbook.write();
        writableworkbook.close();
    }
    catch(NotDirectoryException e) {
        System.err.println(inputpath + " is not a directory." + e);
    }
    catch(IOException e) {
        System.err.println("I/O error." + e);
    }
}
}
  • 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-01T14:29:35+00:00Added an answer on June 1, 2026 at 2:29 pm

    It’s a bug in jxl-2.6.12.jar, use jxl-2.6.10.jar instead.

    Details:

    typo ‘&&’ into ‘&’

    line 493 – line 504 in WritableSheetCopier.java

    if (c != null)
              {
                toSheet.addCell(c);
    
                // Cell.setCellFeatures short circuits when the cell is copied,
                // so make sure the copy logic handles the validated cells        
                if (c.getCellFeatures() != null &
                    c.getCellFeatures().hasDataValidation())
                {
                  validatedCells.add(c);
                }
              }
    

    line 540 – line 551 in WritableSheetCopier.java

    if (c != null)
              {
                toSheet.addCell(c);
    
                // Cell.setCellFeatures short circuits when the cell is copied,
                // so make sure the copy logic handles the validated cells        
                if (c.getCellFeatures() != null &
                    c.getCellFeatures().hasDataValidation())
                {
                  validatedCells.add(c);
                } 
              }
    

    line 990 – line 1001 in SheetCopier.java

    if (c != null)
              {
                toSheet.addCell(c);
    
                // Cell.setCellFeatures short circuits when the cell is copied,
                // so make sure the copy logic handles the validated cells
                if (c.getCellFeatures() != null &
                    c.getCellFeatures().hasDataValidation())
                {
                  validatedCells.add(c);
                }
              }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let me start by saying, I am new to Java programming. I have coded
Let me just start out by saying I am completely new to Java web
Let me start by saying I am fairly new to Java so forgive me
Let me start by saying that I do not advocate this approach, but I
Let me start by saying I'm a huge fan of the elegance of this
Let me start by saying im not 100% the way Im handling this is
Let me start by saying that this app was working fine the day before.
Let me start by saying I'm new at programming, mac osx, and bash. I'm
First off, let me start by saying that I am totally new to working
Let me start out by saying that I'm not a JavaScript developer so this

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.