السلام عليكم ورحمة الله وبركاته
عند تصدير تقرير jasper بهيئة xls لفتحه مباشرة في المستعرض لا يظهر امتداد الملف وهو xls بينما يظهر امتداد الملف بهيئة pdf ويفتح في المستعرض كما ترى في الصورة التالية
لكن بعد حفظ الملف واضافة الامتداد يدويا (تعديل اسم الملف) يفتح في برنامج إكسل أي أن المشكلة اضافة الامتداد للملف .
وهذه هي الأمر التي تعمل مع pdf ولا تعمل مع xls
String fileName = this.getServletContext().getRealPath("reports/exstda.jasper");
Map<String, String> hm;
hm = new HashMap<String, String>();
hm.put("schid", "sch15");
Connection conn;
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/data", "root", "pass");
JasperPrint print = JasperFillManager.fillReport(fileName, hm, conn);
//JRPdfExporter expdf = new JRPdfExporter();
JRXlsExporter exxls = new JRXlsExporter();
//expdf.setParameter(JRExporterParameter.JASPER_PRINT, print);
exxls.setParameter(JRExporterParameter.JASPER_PRINT, print);
//response.setContentType("application/pdf");
response.setContentType("application/xls");
//expdf.setParameter(JRExporterParameter.OUTPUT_STREAM, response.getOutputStream());
exxls.setParameter(JRExporterParameter.OUTPUT_STREAM, response.getOutputStream());
//expdf.exportReport();
exxls.exportReport();
} catch (JRException ex) {
} catch (SQLException ex) {
}
وجزاك الله خيرا
