【发布时间】:2016-04-12 21:03:50
【问题描述】:
我创建了一个类“ReadURL”,用于获取 excel 中存在的 URL。
public class ReadURL
{
static String val;
public String readExcel(String path,String tab,int rowNum,int cellNum) throws Exception
{
FileInputStream fis = new FileInputStream(path);
Workbook wb = WorkbookFactory.create(fis);
Sheet sh = wb.getSheet(tab);
Row row = sh.getRow(rowNum);
String val = row.getCell(cellNum).getStringCellValue();
return val;
}
}
我通过声明值从另一个具有 main 方法的类 'DeadLinks' 调用上述方法。
public class DeadLinks
{
public static void main(String[] args) throws Exception
{
String addr = "C:/Users/sjois/Documents/Automation/TestURLs-Dev.xlsx";
String sht = "USpages";
int r = 2;
int c = 0;
ReadURL url = new ReadURL();
url.readExcel(addr, sht, r, c);
System.out.println(ReadURL.val);
}
}
当我使用 main 方法执行“ReadURL”类并对值进行硬编码时,一切正常。但是,当我尝试从另一个函数调用该函数时,它总是返回“Null”。在编译或运行时我没有收到任何错误。 我哪里错了?
【问题讨论】:
-
这两个类都在同一个包中,我也在导入所有必需的 Apache-poi 包。
标签: java excel selenium apache-poi