3

When I am adding jxl.jar in my eclipse project, it saw convertion error to dalvik format into the console.

Error display in console:

[2010-08-02 19:11:22 - TestApp] trouble writing output: shouldn't happen

[2010-08-02 19:11:22 - TestApp] Conversion to Dalvik format failed with error 2

Code is ok

Below is my code:

import java.io.File;
import java.io.IOException;

import jxl.Cell;
import jxl.CellType;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class ReadExcel {

    private String inputFile;

    public void setInputFile(String inputFile) {
        this.inputFile = inputFile;
    }

    public void read() throws IOException  {
        File inputWorkbook = new File(inputFile);
        Workbook w;
        try {
            w = Workbook.getWorkbook(inputWorkbook);
            // Get the first sheet
            Sheet sheet = w.getSheet(0);
            // Loop over first 10 column and lines

            for (int j = 0; j < sheet.getColumns(); j++) {
                for (int i = 0; i < sheet.getRows(); i++) {
                    Cell cell = sheet.getCell(j, i);
                    CellType type = cell.getType();
                    if (cell.getType() == CellType.LABEL) {
                        System.out.println("I got a label "
                                + cell.getContents());
                    }

                    if (cell.getType() == CellType.NUMBER) {
                        System.out.println("I got a number "
                                + cell.getContents());
                    }

                }
            }
        } catch (BiffException e) {
            e.printStackTrace();
        }
    }



}

Is there anyway to solve this problem?

Thanks Mintu

Hare-Krishna
  • 1,425
  • 3
  • 16
  • 26

1 Answers1

1
CellType type = cell.getType();

if (cell.getType() == cell.LABEL) {
     System.out.println("I got a label " + cell.getContents());
}

if (cell.getType() == cell.NUMBER) {
     System.out.println("I got a number " + cell.getContents());
}

USE cell NOT CellType.

Aleksander Blomskøld
  • 18,374
  • 9
  • 76
  • 82
Kingmot
  • 11
  • 1