android - 如何使用 JXL 2.6.12 jar 读取 excel 文件

标签 android

当我在我的 eclipse 项目中添加 jxl.jar 时,它在控制台中看到了 dalvik 格式的转换错误。

控制台错误显示:

[2010-08-02 19:11:22 - TestApp] 编写输出时遇到问题:不应该发生

[2010-08-02 19:11:22 - TestApp] 转换为 Dalvik 格式失败,出现错误 2

代码没问题

下面是我的代码:

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



}

有什么办法可以解决这个问题吗?

谢谢 敏图

最佳答案

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

使用 cell 而不是 CellType

关于android - 如何使用 JXL 2.6.12 jar 读取 excel 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3387478/

相关文章:

android - 如何为 Apple app store 或 Google play 制作一个 url 以实际打开 app store?

android studio 1.2 gradle 很慢

java - Android 在最小化时复制 Activity,然后最大化

android - 从字节数组生成 ECPublicKey

java - 指定适用于平板电脑和手机的 apk

android - 如何像谷歌地图应用程序一样将谷歌标志移动到透明操作栏上方?安卓

android - 保持计时器在后台滴答作响

php - PHP 文件上的 LIKE 查询问题

android - 下载我的应用程序时出现错误 [DF-AA-33]

android - 如何像下面的结果一样在 android 中编码 url?