0

我正在使用这个库来编译一个 java 程序。我正在使用eclipse,但我也想尝试从命令行编译它(它将通过命令行执行)。它似乎在 Eclipse 上工作。

我已经在命令行中尝试过这个,它似乎正在工作:

javac -cp ../lib/jxl.jar Main.java

但它给了我这个:

Main.java:5: cannot find symbol
symbol  : class Reader
location: class Main
    Reader excel_reader = new Reader();
    ^
Main.java:5: cannot find symbol
symbol  : class Reader
location: class Main
    Reader excel_reader = new Reader();

我只有 2 个类,Main(只有 main 方法)和一个 Reader。这两个文件都在 Eclipse 工作区的 src/ 文件夹下。

读者类:

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 Reader {
  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 (type == CellType.LABEL) {
            System.out.println("I got a label "
                + cell.getContents());
          }

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

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

}

主班

import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    Reader excel_reader = new Reader();
    excel_reader.setInputFile("Excel_Spreadsheets/Dictionary_Part2.xls");
    excel_reader.read();
  }
}
4

0 回答 0