- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个带有静态字段和文本字段的ireport。数据库由大部分数据组成,对于数据库中的单行,有多行数据。所以当我通过java代码将jasper报告导出为PDF格式时正在拉伸(stretch)、阐述和打印整个数据,没有任何丢失的行,但是当我导出到 XLS 时,它丢失了数据,而且单元格的拉伸(stretch)没有发生。我将显示一个图像以便更好地理解。
在上面,即 XLS 格式数据被隐藏或在某种意义上丢失。所以我的问题是当报表导出为 XLS 格式时如何在单元格中显示整个数据。我在下面发布 java 代码。
ServletContext context = request.getServletContext();
String fullPath = context.getRealPath("/WEB-INF/reports/report5.jrxml");
InputStream input = new FileInputStream(new File(fullPath));
JasperDesign jasperDesign = JRXmlLoader.load(input);
System.out.println("Compiling Report Designs");
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
System.out.println("Creating JasperPrint Object");
HashMap<String,Object> map = new HashMap<String,Object>();
map.put("sql",sql);
JasperPrint jasperPrint = JasperFillManager.fillReport (jasperReport,map,conn);
byte bytes[] = new byte[10000];
//String result = JasperRunManager.runReportToHtmlFile("./usertemplates/test.jasper" , parameters, conn);
JRXlsxExporter exporter = new JRXlsxExporter();
ByteArrayOutputStream xlsReport = new ByteArrayOutputStream();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(xlsReport));
SimpleXlsxReportConfiguration configuration = new SimpleXlsxReportConfiguration();
configuration.setWhitePageBackground(true);
configuration.setDetectCellType(true);
configuration.setFontSizeFixEnabled(true);
exporter.setConfiguration(configuration);
exporter.exportReport();
//System.out.println("Size of byte array:"+xlsReport.size());
//bytes = xlsReport.toByteArray();
String fileName = "InvoiceReport.xls";
response.setHeader("Content-Disposition", "inline; filename="
+ fileName);
response.setContentType("application/vnd.ms-excel");
//System.out.println("After JasperPrint = 1");
response.setContentLength(xlsReport.size());
//System.out.println("After JasperPrint = 2");
//xlsReport.close();
//System.out.println("After JasperPrint = 3");
OutputStream outputStream = response.getOutputStream();
System.out.println("After JasperPrint = 4");
xlsReport.writeTo(outputStream);
outputStream.flush();
//outputStream.close();
}
catch(Exception e)
{e.printStackTrace();}
%>
jrxml 代码如下。
report5.jrxml
<detail>
<band height="20" splitType="Prevent">
<textField isStretchWithOverflow="true">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="0" y="0" width="13" height="20" isPrintWhenDetailOverflows="true" uuid="24b49d3f-5c78-4a19-a4d2-e2cbff95a40d">
<property name="net.sf.jasperreports.export.xls.auto.fit.row" value="true"/>
<property name="net.sf.jasperreports.export.xls.auto.fit.column" value="true"/>
</reportElement>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$V{serial number}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="13" y="0" width="242" height="20" isPrintWhenDetailOverflows="true" uuid="4332ae75-6371-4879-b805-9d07254f0784">
<property name="net.sf.jasperreports.export.xls.auto.fit.row" value="true"/>
<property name="net.sf.jasperreports.export.xls.auto.fit.column" value="true"/>
</reportElement>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{DescriptionOfGoods}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="309" y="0" width="86" height="20" isPrintWhenDetailOverflows="true" uuid="54828e8d-bae0-4669-873e-36de8bf54446">
<property name="net.sf.jasperreports.export.xls.auto.fit.row" value="true"/>
<property name="net.sf.jasperreports.export.xls.auto.fit.column" value="true"/>
</reportElement>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{PerUnitPrice}]]></textFieldExpression>
</textField>
<staticText>
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="395" y="0" width="64" height="20" isPrintWhenDetailOverflows="true" uuid="e02408a1-2bcd-4fb9-94d3-ed0c0c1d8ff6">
<property name="net.sf.jasperreports.export.xls.auto.fit.row" value="true"/>
<property name="net.sf.jasperreports.export.xls.auto.fit.column" value="true"/>
</reportElement>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle" markup="none">
<font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[Nos]]></text>
</staticText>
<textField isStretchWithOverflow="true">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="459" y="0" width="96" height="20" isPrintWhenDetailOverflows="true" uuid="00ba44d4-b287-4a29-8bf3-1ad07da760e8">
<property name="net.sf.jasperreports.export.xls.auto.fit.row" value="true"/>
<property name="net.sf.jasperreports.export.xls.auto.fit.column" value="true"/>
</reportElement>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{Quantity} *$F{PerUnitPrice}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="255" y="0" width="54" height="20" isPrintWhenDetailOverflows="true" uuid="d74b9bd4-9608-44a7-b46e-55f39ed0c852">
<property name="net.sf.jasperreports.export.xls.auto.fit.row" value="true"/>
<property name="net.sf.jasperreports.export.xls.auto.fit.column" value="true"/>
</reportElement>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{Quantity}]]></textFieldExpression>
</textField>
</band>
</detail>
最佳答案
首先,您在 jasper 报告中使用已弃用
方法,请考虑更新您的代码:
JRXlsxExporter exporter = new JRXlsxExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
xporter.setExporterOutput(new SimpleOutputStreamExporterOutput(xlsReport));
SimpleXlsxReportConfiguration configuration = new SimpleXlsxReportConfiguration();
configuration.setWhitePageBackground(true);
configuration.setDetectCellType(true);
\\... set all your configuration like above
exporter.setConfiguration(configuration);
exporter.exportReport();
您需要在包含需要位匹配的文本的 textField
中设置 reportElement
的属性。
<property name="net.sf.jasperreports.export.xls.auto.fit.row" value="true"/>
<property name="net.sf.jasperreports.export.xls.auto.fit.column" value="true"/>
如果这不能按预期工作,您的解决方案是:
使 Excel 更改字体大小(以适合)
configuration.setFontSizeFixEnabled(true)
Flag for decreasing font size so that texts fit into the specified cell height.
net.sf.jasperreports.export.xls.column.width
,具有以像素为单位测量的整数值的属性
如果您仍然不满意,请转至 apache-poi ,加载工作簿并根据需要进行修改......
关于java - 将 jasper 报告导出为 XLS 格式时,未发生单元格扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35054440/
我正在使用 Python 2.76 向 .aspx 网页提交查询并通过 BeautifulSoup 获取结果,并希望将它们存储到 Excel 电子表格中。 import mechanize impor
我正在学习使用 Hadoop 执行大数据相关操作。 我需要对拆分为 8 个 xls 文件的数据集集合执行一些查询。每个 xls 文件都有多个工作表,查询只涉及其中一个工作表。 数据集可以在这里下载:h
我有一个 excel 文件,但文件大小太大,您有什么建议可以让我们以相同的格式减小文件大小吗? 最佳答案 有一些常见技巧可以减小 Excel 文档的大小,同时保持 Excel 格式。这取决于文件的具体
我有多个目录,每个目录包含任意数量的 .xls 文件。我想获取任何给定目录中的文件并将它们合并到一个 .xls 文件中,使用文件名作为选项卡名称。例如,如果有文件 NAME.xls、AGE.xls、L
使用下面的 Python 测试代码,我试图将 Excel (*.xls) 文件中唯一的工作表复制到一个包含一个工作表的新 Excel 文件中。 输入电子表格如下所示: from copy import
我有一个 xls 文件,其中包含 15 张数据,我想将所有数据复制到另一个 xls 文件中。我有很多这样的文件,所以我想使用宏 vba 编码对其进行自定义。我想在第一张纸上设计按钮,它会运行宏代码并将
我正在尝试从 xls 中读取数据,该数据运行良好 java.io.File f1=new java.io.File("E:/SELENIUM DATA/First_P1/DATA_SHEET.x
我有一个文件 .XLS 扩展名,但保存为 XMl 电子表格 2003 ,想要读取该文件并使用 java 代码将其转换为 .XLS 扩展名,我的代码如下 - 公共(public)类 ExcelImpor
我已经创建了 Servlet,它下载 POI XLS 文件,在第一个 get/post 请求时,新文件是使用sheet0下载的。当我执行第二个请求时,正在下载两张新文件,sheet0 是上一个请求,s
我有大量格式为:YYYYDDMM_rest_of_filename.xls 的 excel 文件 我如何使用 ruby 在 YYYYMMDD_rest_of_filename.xls 的可能数量较
我将 xlsx 文件保存在 firefox 中,浏览器将其识别为 97-2003 工作簿 (.xls) 当我打开 xls 文件时,它会生成弹出窗口 我也在不同的机器上尝试过这个,它在 firefox
伙计们。我在 DB 有日期作为字符串“d/m/Y”。 当我将此日期输入 Excel 时,它会显示正常日期,例如 2000 年 3 月 10 日,但是当我单击单元格时,它会显示值 '03/10/2000
我正在研究 INFORMIX 4GL 程序。该程序生成输出文本文件。这是输出的示例: Lot No|Purchaser name|Billing|Payment|Deposit|Balance|
代码如下: <%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%> <%
我的应用程序正在从 MYSQL 动态获取数据并显示。问题是我什至必须选择“导出到 Xls”文件。这些文件应该是 A4 大小,所以我应该自定义 Xls 文件中内容的字体大小以适应 A4 大小。如果可能的
我必须运行一些 SQL 查询并将结果放入电子表格中。由于我处于 Spring/Java 环境中,因此我打算使用 JDBC 运行查询、迭代 ResultSet,并使用 Jakarta POI 创建一个简
我有一个包含多张工作表的 Excel 电子表格。格式如下: Date A B C D E F
我正在使用 jquery 数据表插件来显示数据。我添加了文件另存为 excel、csv 和 pdf 的选项。 虽然它允许我将表格内容保存为文件。但在 excel 和 csv 情况下,它都会将文件保存为
我正在尝试弄清楚如何读取 XLS 文档的内容并且我能够很好地获取字节,但我不知道从这里到哪里去。尝试 [[NSString alloc] initWithBytes:data.bytes length
在我的应用程序中,我需要以预定义格式导出到 xls 文件。 所以我刚刚集成了 php_excel2007。我正在使用一个具有预定义格式的模板。 问题 这里的单元格数据可能会动态变化。如果数据远大于单元
我是一名优秀的程序员,十分优秀!