2016-05-11 19 views
6

私はApache POI 2.5.1を使って.xlsファイルをHSSFWorkbookにエクスポートしていました。 Apache POIを3.13に更新したので、ファイルをSXSSFWorkbookでエクスポートしていますが、そのファイルは破損しています。weblogicでxlsxをエクスポートする:weblogicで:ファイル形式または拡張子が無効です

MS Excelがファイルを開けませんでしたファイル形式または拡張子が無効ですエラー。

この問題は​​サーバでのみ発生することに注意してください。JBossで問題なく動作します。

誰でも私がここで間違っていることを助けることができますか?

コード:

List<JRField> fields = ds.getFields(); 
    SXSSFWorkbook wb = new SXSSFWorkbook(); 
    SXSSFSheet sheet = wb.createSheet("Sheet1"); 

    try { 
     CellStyle cellStyle   = wb.createCellStyle(); 
     CellStyle cellStyleColName = wb.createCellStyle(); 
     CellStyle cellStyleTitle = wb.createCellStyle(); 

     Font boldFont = wb.createFont(); 
     boldFont.setFontHeightInPoints((short)16); 
     boldFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); 

     // Cell Style for body 
     cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("($#,##0_);[Red]($#,##0)")); 
     cellStyle.setWrapText(true); 

     // Cell Style for Column Names 
     cellStyleColName.setDataFormat(HSSFDataFormat.getBuiltinFormat("($#,##0_);[Red]($#,##0)")); 
     cellStyleColName.setAlignment(HSSFCellStyle.ALIGN_CENTER); 
     cellStyleColName.setBorderTop(HSSFCellStyle.BORDER_MEDIUM); // single line border 
     cellStyleColName.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM); // single line border 

     // Cell Style for Title 
     cellStyleTitle.setDataFormat(HSSFDataFormat.getBuiltinFormat("($#,##0_);[Red]($#,##0)")); 
     cellStyleTitle.setAlignment(HSSFCellStyle.ALIGN_CENTER); 
     cellStyleTitle.setFont(boldFont); 

     // Creating Title Row 
     Row row1 = sheet.createRow((short) 0); 

     // Creating the Title line 
     Cell cell1 = row1.createCell((short) 0); 
     cell1.setCellValue("Demo Title"); 
     cell1.setCellStyle(cellStyleTitle); 

     // Title Region 
     CellRangeAddress regionTitle = new CellRangeAddress( (short) 0,  // From Row 
       (short) 0,         // From Col 
       (short) 0,         // To Row 
       (short) (this.displayCols.size()-1)   // To Col 

     ); 
     sheet.addMergedRegion(regionTitle); 

     // Column Name Row 
     int j =0; 
     Row row2 = sheet.createRow((short) 1); 
     for (ReportColumn col : this.displayCols) 
     { 
      Cell cell2 = row2.createCell((short) j++); 
      cell2.setCellValue(col.getDisplayName()); 
      cell2.setCellStyle(cellStyleColName); 
     } 

     int i =2; 
     while (ds.next()) { 
      Row rows = sheet.createRow((short) 0 + i); 
      int k = 0; 
      for (JRField field : fields) { 
       String fieldAsString = (ds.getFieldValue(field) != null ? ds.getFieldValue(field).toString():null); 
       Cell cell = rows.createCell((short) k++); 
       cell.setCellStyle(cellStyle); 
       cell.setCellValue(fieldAsString); 
      } 
      i++; 
      if (i > RECORD_LIMIT_FROM_POI){ 
       log.info("Row limit from poi reached #1048576 and exported data is truncated."); 
       break; 
      } 
     } 

     wb.write(os); 
    } 
    catch (Exception e) { 
     log.error("error in createXlsFile method", e); 
    } 

失敗の試み:

    のWebLogicのカスタムMIMEマッピング・ファイル内の vnd.openxmlformats-officedocument.spreadsheetml.sheet
  1. からapplication/vnd.ms-excel からのレスポンスヘッダ内の
  2. 更新MIMEタイプを追加しましたxlsx=vnd.openxmlformats-officedocument.spreadsheetml.sheet
+0

どのweblogicバージョンですか? 12.1.3? – Slettal

+1

@Slettalその10.3.5.0 –

+2

大丈夫です。あなたのコードはWL 12.1.3で問題なく動作します。 10.3.5のインストールがありません:( – Slettal

答えて

0

これは、より多くのリソース重いかもしれないが、あなたは試してみました:代わりにSXSSFの

XSSFWorkbook wb = new SXSSFWorkbook(); 
XSSFSheet sheet = wb.createSheet("Sheet1"); 

を。

さまざまなタイプの間でいくつかの議論があります:HSSFWorkbook vs XSSFWorkbook and the advantages/disadvantages of XSSFWorkbook and SXSSFWorkbook?

+0

XSSFWorkBookも試してみましたが、動作しませんでした。 –

関連する問題