亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法從數字單元格java中獲取文本值

無法從數字單元格java中獲取文本值

開滿天機 2022-01-19 17:02:58
當我嘗試讀取 excel 表時,我遇到了這個代碼問題,如果它包含它將讀取的文本,但它不讀取它的數字并給我這個錯誤 Cannot get a text value from a numeric cell javapublic static void main(String[] args) throws IOException, Exception {    /*WebDriver dr;    // TODO Auto-generated method stub         dr = new FirefoxDriver();        dr.get("https://www.example.com/");        ArrayList<String> username=readExcelData(0);        ArrayList<String> pass=readExcelData(1);        for(int i=0; i<username.size();i++) {        dr.findElement(By.id("email")).sendKeys(username.get(i));        dr.findElement(By.id("pass")).sendKeys(pass.get(i));        dr.findElement(By.id("loginbutton")).click();        Thread.sleep(6000);        dr.findElement(By.id("email")).clear();        dr.findElement(By.id("pass")).clear();        }*/// it work with txt //readExcelData(0);// it will not work with the number //readExcelData(1);}public static  ArrayList<String> readExcelData(int colNo) throws IOException {    FileInputStream fis= new FileInputStream("C:\\dat.xls");    HSSFWorkbook wb=new HSSFWorkbook(fis);    HSSFSheet s=wb.getSheet("sh1");    Iterator<Row> rowIterator=s.iterator();    rowIterator.next();    ArrayList<String> list=new ArrayList<String>();    while (rowIterator.hasNext()) {        list.add( rowIterator.next().getCell(colNo).getStringCellValue());    }    System.out.println("List :::"+list);    return list;}
查看完整描述

1 回答

?
慕哥9229398

TA貢獻1877條經驗 獲得超6個贊

試試下面的代碼:


public static  ArrayList<String> readExcelData(int colNo) throws IOException {

            FileInputStream fis= new FileInputStream("C:\\dat.xls");

            HSSFWorkbook wb=new HSSFWorkbook(fis);

            HSSFSheet s=wb.getSheet("sh1");

            Iterator<Row> rowIterator=s.iterator();

            rowIterator.next();

            ArrayList<String> list=new ArrayList<String>();

            DataFormatter formatter = new DataFormatter();


            while (rowIterator.hasNext()) {

                 String val = formatter.formatCellValue(rowIterator.next().getCell(colNo));

                list.add(val);

            }

            System.out.println("List :::"+list);

            return list;

        }


查看完整回答
反對 回復 2022-01-19
  • 1 回答
  • 0 關注
  • 236 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號