Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从excel工作表中读取的代码无效_Java_Selenium_Excellibrary - Fatal编程技术网

Java 从excel工作表中读取的代码无效

Java 从excel工作表中读取的代码无效,java,selenium,excellibrary,Java,Selenium,Excellibrary,我有下面的代码从一个测试文件中读取并在控制台上打印它,但它没有打印任何东西,我不知道如何检查它生成的错误。我正在使用java、selenium、ie 10、win 8 public class Rowcount { public static void main(String[] args) throws BiffException, IOException { FileInputStream exo=new FileInputStream("E:\\Test filee

我有下面的代码从一个测试文件中读取并在控制台上打印它,但它没有打印任何东西,我不知道如何检查它生成的错误。我正在使用java、selenium、ie 10、win 8

public class Rowcount {
    public static void main(String[] args) throws BiffException, IOException {
        FileInputStream exo=new FileInputStream("E:\\Test filee.xlsx");
        Workbook wbo=Workbook.getWorkbook(exo);
        Sheet wso=wbo.getSheet(0);
        int lastrownum;
        lastrownum= wso.getRows();
        System.out.println(lastrownum);
    }
}

你在用JExcelApi吗?如果是这样,我认为它不支持Excel2007及以上版本。你可以考虑查看。

JXL没有为XLSX工作。尝试改用ApachePOI实现

这个代码被错误引用了

FileInputStream exo=new FileInputStream(""E:\\Test filee.xlsx"");

您需要删除额外的报价

以下代码适用于我:

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 ReadExcell {
public static void main(String[] args) {
ReadExcell.ExcelFile("D:\\rptViewer.xls");
}

/*
* Read excel file using j excel file
*/
public static String ExcelFile(String path){
StringBuilder excelContent = new StringBuilder();

try
{
Workbook workbook = Workbook.getWorkbook(new File(path));
Sheet sheet = workbook.getSheet(0);

excelContent = new StringBuffer();

for(int rows = 0 ; rows < sheet.getRows() ; rows++){
StringBuffer row = new StringBuffer();
for(int colums = 0 ; colums < sheet.getColumns() ;colums++){
  Cell cell = sheet.getCell(colums, rows);
if(cell.getType() == CellType.LABEL){
row.append(cell.getContents()+ ",");
}else
if(cell.getType() == CellType.NUMBER){
row.append(cell.getContents()+ ",");
}
}

excelContent.append(row.toString());
System.out.println(row.toString());
}

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

return excelContent.toString();
}
}    
导入java.io.File;
导入java.io.IOException;
进口jxl.Cell;
导入jxl.CellType;
进口jxl.Sheet;
导入jxl.工作簿;
导入jxl.read.biff.BiffException;
公共类ReadExcell{
公共静态void main(字符串[]args){
ReadExcell.ExcelFile(“D:\\rptViewer.xls”);
}
/*
*使用j excel文件读取excel文件
*/
公共静态字符串文件(字符串路径){
StringBuilder excelContent=新建StringBuilder();
尝试
{
工作簿=工作簿.get工作簿(新文件(路径));
工作表=工作簿。获取工作表(0);
excelContent=新的StringBuffer();
对于(int rows=0;rows
“E:\\Test filee.xlsx”引用两次。。。是吗??。你有什么异常吗?确定正确吗?“”E:\\Test filee.xlsx“”对不起,我在编译之前用代码编辑了这个。