7

私はいくつかのかなり複雑なExcelファイルに取り組んでいて、シートのコピーで問題に遭遇しました。完全に空白ではないシートをコピーしようとすると、次のメッセージが表示されます。

Exception in thread "main" java.lang.NullPointerException
     at jxl.write.biff.WritableSheetCopier.shallowCopyCells(WritableSheetCopier.java:499)
     at jxl.write.biff.WritableSheetCopier.copySheet(WritableSheetCopier.java:239)
     at jxl.write.biff.WritableSheetImpl.copy(WritableSheetImpl.java:1622)
     at jxl.write.biff.WritableWorkbookImpl.copySheet(WritableWorkbookImpl.java:987)
     at excelCalc.main(excelCalc.java:18)

ここでの問題は何だろうと思います。情報が含まれているシートに使用できない場合、なぜ「.copySheet(」関数が存在するのでしょうか。問題をより単純なスケールで再現するために、以下のコードを作成しました。出力は次のようになります。セル(0,0)に「test」というラベルが付いた2つの同一のシートがあります。一方のシートには「Flows」、もう一方のシートには「copy」というラベルが付いています。これがこのnullポインタを与える理由について何か考えはありますか?

import java.io.File;

import jxl.*;
import jxl.write.*;

public class excelCalc
{
    public static void main(String[] args) throws Exception
    {
        WritableWorkbook outputBook = Workbook.createWorkbook(new File("C:/Users/Kevin Brey/CS243/ExcelTest/files/output", "output.xls"));

        WritableSheet rSheet = outputBook.createSheet("Flows", 0);

        rSheet.addCell(new Label(0, 0, "test"));
        outputBook.copySheet(0, "copy", 0);
        outputBook.write();
        outputBook.close();
    }
}

編集:このコードも同じ例外を与えます:

import java.io.File;

import jxl.*;
import jxl.write.*;

public class excelCalc
{
    public static void main(String[] args) throws Exception
    {
        WritableWorkbook outputBook = Workbook.createWorkbook(new File("C:/Users/Kevin Brey/CS243/ExcelTest/files/output", "output.xls"));

        WritableSheet sheet1 = outputBook.createSheet("Sheet1", 0);
        WritableSheet sheet2 = outputBook.createSheet("Sheet2", 1);

        sheet1.addCell(new Label(0, 0, "Label1"));
        sheet2.addCell(new Label(0, 0, "Label2"));

        outputBook.copySheet(0, "Copy", 1);

        outputBook.write();
        outputBook.close();
    }
}

何が間違っているのかという私の考えの1つは、シートが開いていて編集されているため、コピーできないということです。しかし、私はこれを回避する方法を本当に知りません。

4

2 に答える 2

10

これはjxl-2.6.12.jarのバグです。代わりに、jxl-2.6.10.jarを使用してください。

詳細:

typo'&&' into'&'

493行目-WritableSheetCopier.javaの504行目

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);
            }
          }

WritableSheetCopier.javaの540行目-551行目

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);
            } 
          }

990行目-SheetCopier.javaの1001行目

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);
            }
          }
于 2012-04-11T05:51:48.840 に答える
0

コピーシートが空です。コピーする前に、コピーシートにいくつかのセルを追加してください

于 2012-03-31T21:45:04.283 に答える