Jasper生成了Excel文件错误" Excel在...中找到了不可读的内容。

时间:2015-04-30 10:27:21

标签: java excel jasper-reports

我使用JavaJasper生成.xlsx格式的报告。 我成功了,我的应用程序中有组件,用数据创建实际报告。

最近我尝试添加另一个组件并且报告生成成功,但生成的.xslx文件不会以MS Excel或其他任何方式打开。

代码部分如下。

    ArrayList<ReportBean> reportBean =  new ArrayList<ReportBean>();

    response.setHeader("Content-Disposition",  "attachment;filename=BudgetaryQuote.xlsx");
    response.setContentType("application/xlsx");
    OutputStream outStream = response.getOutputStream();

    Report report = new Report(template, "xlsx", reportBean, outStream);
    //Report(String template, String format, ArrayList dataList,OutputStream outputStream) 
    report.generateReport();

在generateReport()中,

        InputStream inputStream = new FileInputStream(new File(this.template));  
        JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(this.dataList); 
        JasperDesign jasperDesign = JRXmlLoader.load(inputStream); 
        JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign); 
        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, beanColDataSource);

        if(this.format.equalsIgnoreCase(XLSX)) {

            JRXlsxExporter Xlsxexporter = new JRXlsxExporter();
            Xlsxexporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
            Xlsxexporter.setParameter(JRExporterParameter.OUTPUT_STREAM,  outputStream);
            Xlsxexporter.exportReport();            

        }

.jrxml文件(它几乎是空白的)

     <?xml version="1.0" encoding="UTF-8"?>
     <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="timeSheetDetailedReport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="4ffef809-ea2d-4533-a0b9-bdd2d055afbe">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<background>
    <band splitType="Stretch"/>
</background>
<title>
    <band height="79" splitType="Stretch"/>
</title>
<pageHeader>
    <band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
    <band height="61" splitType="Stretch"/>
</columnHeader>
<detail>
    <band height="125" splitType="Stretch"/>
</detail>
<columnFooter>
    <band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
    <band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
    <band height="42" splitType="Stretch"/>
</summary>

图像中出现错误。 "Excel found unreadable content in filename.xls. Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes."

如何检查文件有什么问题?

enter image description here

0 个答案:

没有答案