如何在填充Jasper中的报告之前添加JRParagraph.DEFAULT_TAB_STOP_WIDTH

时间:2014-01-30 11:40:45

标签: java jasper-reports

我正在根据用户输入动态生成jrxml文件并尝试填充报告。 它适用于某些情况。当用户添加更多列系统时会抛出以下异常:

net.sf.jasperreports.engine.util.ParagraphUtil.getFirstTabStop(ParagraphUtil.java:208) 
net.sf.jasperreports.engine.fill.TextMeasurer.renderNextLine(TextMeasurer.java:1009) 
net.sf.jasperreports.engine.fill.TextMeasurer.renderParagraph(TextMeasurer.java:717) 
net.sf.jasperreports.engine.fill.TextMeasurer.measure(TextMeasurer.java:416) 
net.sf.jasperreports.engine.fill.JRFillTextElement.chopTextElement(JRFillTextElement.java:504) 
net.sf.jasperreports.engine.fill.JRFillTextField.prepare(JRFillTextField.java:593) 
net.sf.jasperreports.engine.fill.JRFillElementContainer.prepareElements(JRFillElementContainer.java:328) 
net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:377) 
net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:351) 
net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2039) 
net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:771) 
net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportContent(JRVerticalFiller.java:301) 
net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:148) 
net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:909) 
net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:841) 
net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:88) 
net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:653) 
net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:634) 
net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:956)

我正在使用 JasperReports 4.7 库。

以下是填充和放大的java代码导出jrxml。

InputStream inputStream = null;
    JasperPrint jasperPrint = null;

    JExcelApiExporter  apiExporter = null;
    HashMap map = new HashMap();
    JRSwapFileVirtualizer virtualizer = null;

    try {

        inputStream = new FileInputStream(jasperFilePath);

        if (reportType.equals("REPORTGENERATOR")) {
            map.put(JRParameter.IS_IGNORE_PAGINATION, Boolean.TRUE);            
        }

        map.put("REALPATH", realPath);

        String directory = realPath+"tempdocs";
        JRSwapFile swapFile = new JRSwapFile(directory, 1024, 100);
        virtualizer = new JRSwapFileVirtualizer(50, swapFile, true);
        map.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);               
        jasperPrint = JasperFillManager.fillReport(inputStream, map, resultSetDataSource);


        apiExporter = new JExcelApiExporter();
        apiExporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
        apiExporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
        apiExporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS, Boolean.TRUE);
        apiExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
        apiExporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, 
                realPath + "tempdocs/jasper/" + reportName + ".xls");


        apiExporter.exportReport();

    } catch (Exception e) {
        e.printStackTrace();            
    }finally{
        try{
            if (virtualizer != null) virtualizer.cleanup();
            inputStream.close();
        }catch(Exception e){
            e.printStackTrace();
        }
    }

建议我处理这个问题的好方法。

1 个答案:

答案 0 :(得分:0)

我在查询的每个varchar列中使用replace(col,chr(9),' ')用空格替换制表符。现在它工作正常。 但我知道这不是一个正确的答案。这只是一个解决方案。