2017-09-20 12 views
1

以下の関数を使ってExcelデータを設定しましたが、データを設定しています。ファイルがcoruptedなっていると私はスレッドで例外としてerrrorを取得して "メイン" java.lang.NoClassDefFoundErrorが:ORG/openxmlformats /スキーマ/ spreadsheetml/x2006// CTDxfsメイン$ 1 My Jarsexcelでセルデータを設定できません

public boolean setCellData(String sheetName,String colName,int rowNum, String data){ 
    try{ 
    fis = new FileInputStream(path); 
    workbook = new XSSFWorkbook(fis); 

    if(rowNum<=0) 
     return false; 

    int index = workbook.getSheetIndex(sheetName); 
    int colNum=-1; 
    if(index==-1) 
     return false; 


    sheet = workbook.getSheetAt(index); 


    row=sheet.getRow(0); 
    for(int i=0;i<row.getLastCellNum();i++){ 
     //System.out.println(row.getCell(i).getStringCellValue().trim()); 
     if(row.getCell(i).getStringCellValue().trim().equals(colName)) 
      colNum=i; 
    } 
    if(colNum==-1) 
     return false; 

    sheet.autoSizeColumn(colNum); 
    row = sheet.getRow(rowNum-1); 
    if (row == null) 
     row = sheet.createRow(rowNum-1); 

    cell = row.getCell(colNum); 
    if (cell == null) 
     cell = row.createCell(colNum); 


    cell.setCellValue(data); 

    fileOut = new FileOutputStream(path); 

    workbook.write(fileOut); 

    fileOut.close();  

    } 
    catch(Exception e){ 
     e.printStackTrace(); 
     return false; 
    } 
    return true; 
} 
+0

投稿全体 –

+0

エラーの完全なスタックトレースを表示します。 –

答えて

1

あなたのことが必要read the Apache POI FAQ!。具体的には、Apache POI FAQ entry on "I'm using the poi-ooxml-schemas jar, but my code is failing with "java.lang.NoClassDefFoundError: org/openxmlformats/schemas/something"から:だから

To use the new OOXML file formats, POI requires a jar containing the file format XSDs, as compiled by XMLBeans. These XSDs, once compiled into Java classes, live in the org.openxmlformats.schemas namespace.

There are two jar files available, as described in the components overview section. The full jar of all of the schemas is ooxml-schemas-1.3.jar, and it is currently around 15mb. The smaller poi-ooxml-schemas jar is only about 4mb. This latter jar file only contains the typically used parts though.

Many users choose to use the smaller poi-ooxml-schemas jar to save space. However, the poi-ooxml-schemas jar only contains the XSDs and classes that are typically used, as identified by the unit tests. Every so often, you may try to use part of the file format which isn't included in the minimal poi-ooxml-schemas jar. In this case, you should switch to the full ooxml-schemas-1.3.jar. Longer term, you may also wish to submit a new unit test which uses the extra parts of the XSDs, so that a future poi-ooxml-schemas jar will include them.

、短期的に、あなただけの大規模(かつ完全な)ooxml-schemasooxml-schemas-1.3.jarpoi-ooxml-schemas瓶から切り替える必要があります。長期的には、目的のCTクラスを使用するApache POIプロジェクトにjunitテストを提出する必要があります。そのクラスは、将来のリリースではより小さいpoi-ooxml-schemas jarに自動的に含まれます。

関連する問題