2016-05-11 11 views
6

इससे पहले मैं HSSFWorkbook का उपयोग कर .xls फ़ाइल निर्यात करने के लिए अपाचे पीओआई 2.5.1 का उपयोग कर रहा था। अद्यतन Apache POI के साथ 3.13 करने के लिए मैं .xlsxSXSSFWorkbook लेकिन इसकी भ्रष्ट फ़ाइल निर्यात का उपयोग कर फ़ाइल निर्यात कर रहा हूँ।वेबलॉग पर apache poi 3.13 का उपयोग कर xlsx निर्यात करना: फ़ाइल प्रारूप या एक्सटेंशन मान्य नहीं है

एमएस एक्सेल फ़ाइल प्रारूप या एक्सटेंशन के साथ फ़ाइल खोलने में विफल रहा त्रुटि मान्य नहीं है।

ध्यान दें कि इस समस्या का मुझे केवल WebLogic सर्वर पर सामना करना पड़ रहा है, यह 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); 
    } 

विफल प्रयास:

  1. अपडेट किया गया माइम प्रतिक्रिया हेडर में application/vnd.ms-excel से vnd.openxmlformats-officedocument.spreadsheetml.sheet
  2. करने के लिए कस्टम माइम मैपिंग फ़ाइल में वेबलॉजिक
  3. के लिए प्रकार जोड़ा गया xlsx=vnd.openxmlformats-officedocument.spreadsheetml.sheet
+0

कौन सा संस्करण WebLogic:

विभिन्न प्रकार यहाँ के बीच कुछ चर्चा भी नहीं है? 12.1.3? – Slettal

+1

@Slettal इसके 10.3.5.0 –

+2

ठीक है, ठीक है आपका कोड डब्लूएल 12.1.3 पर समस्याओं के बिना काम करता है। एक 10.3.5 स्थापना :( – Slettal

उत्तर

0

यह और अधिक संसाधन भारी हो सकता है, लेकिन आप की कोशिश की है:

XSSFWorkbook wb = new SXSSFWorkbook(); 
XSSFSheet sheet = wb.createSheet("Sheet1"); 
SXSSF के बजाय

HSSFWorkbook vs XSSFWorkbook and the advantages/disadvantages of XSSFWorkbook and SXSSFWorkbook?

+0

मैं भी XSSFWorkBook की कोशिश की है, न काम कर प्रयास करें। –

संबंधित मुद्दे