2015-12-28 52 views
-2

的Java類如何在excel文件中編寫?

 public void CandidateUpload(String path) { 
     try { 
     FileInputStream file = new FileInputStream(new File(path)); 

     XSSFWorkbook workbook = new XSSFWorkbook(file); 
     XSSFSheet sheet = workbook.getSheetAt(0); 

     int c = 1; 

     while (c < sheet.getPhysicalNumberOfRows()) { 
      Row row1 = sheet.getRow(c); 

      String firstname = row1.getCell(5).toString().trim(); 
      String lastname = row1.getCell(6).toString().trim(); 

      System.out.println("%%**---**" + firstname); 
      System.out.println("%%**----**" + lastname); 

      Cell name = row1.createCell(12); 
      name.setCellValue("gokul"); 

      // sheet.getRow(12).getCell(11).setCellValue("gokul"); 

      c++; 
      } 
      } catch (Exception e) { 
     System.out.println("Exception" + e); 
     e.printStackTrace(); 
     } finally { 
     }} 


    error:28-Dec-2015 20:34:01.914 WARNING [http-nio-8084-exec-67]      .opensymphony.xwork2.util.logging.commons.CommonsLogger.warn Content-Type not allowed: file "300634.xlsx" "upload_76a722f4_151e90da166__7fff_00000002.tmp" application/vnd.openxmlformats-officedocument.spreadsheetml.sheet 

警告*********** NetBeans的HTTP監視器************ 請求不能被記錄很可能是因爲NetBeans的HTTP監視器模塊被禁用。

+0

java.lang.NoSuchFieldException:resourceEntries –

+2

能否請您解釋一下什麼問題,你用更多的細節面對? –

+0

如何在excel表格中插入值? –

回答

1

看起來你錯過來電寫

workbook.write(java.io.OutputStream中的流)

從如何引導:

一旦您已生成工作簿,可以通過從Workbook實例調用write(outputStream)並將其傳遞給OutputStream(例如FileOutputStream或ServletOutputStream)來將其寫出。您必須自己關閉OutputStream。 HSSF不會爲你關閉它。

退房的POI Quick GuideHow To Guide