我已经搜索了很多,我是新的贾斯珀报告。我制作了一个简单的jasper报表项目(在jaspersoft studio中),该报表从dataAdapter.xml中获取数据,我将它创建为“JRDataSource的自定义实现”,并将其作为工厂类编写如下:
package mydapackage;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Random;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;
public class MyImplementation implements JRDataSource {
static DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd MMMM yyyy");
static LocalDate localDate = LocalDate.now();
static Random random = new Random();
static String codigoVer = new BigInteger(50, random).toString(32);
private static final Integer[] FOJAS_ARRAY = { 25 };
private static final Integer[] NUMEROTITULO_ARRAY = { 86 };
private static final Integer[] ANOTITULO_ARRAY = { 2009 };
private static final String[] REGISTRO_ARRAY = { "Propiedad" };
private static final String[] VIGENCIA_ARRAY = { "Con Vigencia" };
private static final Integer[] PRECIO_ARRAY = { 5000 };
private static final String[] FECHA_ARRAY = { dtf.format(localDate) };
private static final Integer[] ANOACTUAL_ARRAY = { 2017 };
private static final String[] BOLETA_ARRAY = { "78965458" };
private static final String[] ALEATORIO = { codigoVer };
private int counter = -1;
@Override
public boolean next() throws JRException {
if (counter < FOJAS_ARRAY.length - 1) {
counter++;
return true;
}
return false;
}
@Override
public Object getFieldValue(JRField jrField) throws JRException {
if (jrField.getName().equals("FOJAS"))return FOJAS_ARRAY[counter];
else if (jrField.getName().equals("NUMEROTITULO"))return NUMEROTITULO_ARRAY[counter];
else if (jrField.getName().equals("ANOTITULO"))return ANOTITULO_ARRAY[counter];
else if (jrField.getName().equals("REGISTRO"))return REGISTRO_ARRAY[counter];
else if (jrField.getName().equals("VIGENCIA"))return VIGENCIA_ARRAY[counter];
else if (jrField.getName().equals("PRECIO"))return PRECIO_ARRAY[counter];
else if (jrField.getName().equals("FECHA"))return FECHA_ARRAY[counter];
else if (jrField.getName().equals("ANOACTUAL"))return ANOACTUAL_ARRAY[counter];
else if (jrField.getName().equals("BOLETA"))return BOLETA_ARRAY[counter];
else if (jrField.getName().equals("COD_VERIFICACION"))return ALEATORIO[counter];
return "";
}
public static JRDataSource getDataSource() {
return new MyImplementation();
}
}
我的数据适配器名称只是“dataadapter.xml”,我的jasper报告文件名是:“caratula.jrxml”。下面是代码:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1 -->
<!-- 2017-06-13T11:11:43 -->
<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="caratula_def" language="groovy" pageWidth="612" pageHeight="935" columnWidth="556" leftMargin="28" rightMargin="28" topMargin="28" bottomMargin="28" uuid="3617c6de-583f-41d0-bc9a-92ec55a4cddb">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="DataAdapter.xml"/>
<property name="ireport.zoom" value="1.5"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="488"/>
<field name="FOJAS" class="java.lang.Integer"/>
<field name="NUMEROTITULO" class="java.lang.Integer"/>
<field name="ANOTITULO" class="java.lang.Integer"/>
<field name="REGISTRO" class="java.lang.String"/>
<field name="VIGENCIA" class="java.lang.String"/>
<field name="PRECIO" class="java.lang.Integer"/>
<field name="FECHA" class="java.lang.String"/>
<field name="ANOACTUAL" class="java.lang.Integer"/>
<field name="BOLETA" class="java.lang.String"/>
<field name="COD_VERIFICACION" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band splitType="Stretch"/>
</title>
<pageHeader>
<band splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band splitType="Stretch"/>
</columnHeader>
<detail>
<band height="799" splitType="Stretch">
<image>
<reportElement x="137" y="267" width="287" height="260" uuid="46f3298b-64ec-4179-880e-4b5f40dd71f2"/>
<imageExpression><![CDATA["C:\\firma\\ESCUDO.png"]]></imageExpression>
</image>
<rectangle>
<reportElement mode="Transparent" x="51" y="69" width="453" height="619" uuid="e6f767f1-8f41-4f03-9bc0-9d6126b8e23e"/>
</rectangle>
<image>
<reportElement x="51" y="82" width="123" height="111" uuid="98fec185-0f0b-44de-bd5e-de0cdd7c79cb"/>
<imageExpression><![CDATA["C:\\firma\\conservador-logo-of.png"]]></imageExpression>
</image>
<staticText>
<reportElement x="251" y="692" width="253" height="40" uuid="73f3aa14-49a6-47fa-a6e6-46d659d76239"/>
<textElement textAlignment="Justified">
<font size="6"/>
</textElement>
<text><![CDATA[Documento incorpora firma electrónica avanzada conforme a Ley N°19.799.
La vigencia de la firma electrónica en el documento, al igual que la integridad y autenticidad del mismo, deben ser verificados en www.conservadortemuco.cl, donde estará disponible por 90 días contados desde la fecha de su emisión.
Documento impreso es sólo una copia del documento original.]]></text>
</staticText>
<staticText>
<reportElement x="162" y="100" width="335" height="28" uuid="fbdf830f-a257-4aee-997b-86cdd2dd39b2"/>
<textElement textAlignment="Right">
<font size="16" isBold="true"/>
</textElement>
<text><![CDATA[Conservador de Bienes Raíces de Temuco]]></text>
</staticText>
<staticText>
<reportElement x="342" y="124" width="155" height="12" uuid="caafa104-4346-4480-be66-e52999cc1d00"/>
<textElement textAlignment="Right">
<font size="8"/>
</textElement>
<text><![CDATA[Vicuña Mackenna 0361, Temuco]]></text>
</staticText>
<staticText>
<reportElement x="334" y="135" width="163" height="13" uuid="a69883f2-c2f0-43d8-a51b-94e1301d594d"/>
<textElement textAlignment="Right">
<font size="8"/>
</textElement>
<text><![CDATA[http://www.conservadortemuco.cl]]></text>
</staticText>
<textField isBlankWhenNull="true">
<reportElement x="91" y="225" width="251" height="23" uuid="6fc40966-65db-4d96-b741-fb7688154b8b"/>
<textElement>
<font size="16" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Registro de "+$F{REGISTRO}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="91" y="267" width="243" height="23" uuid="f5d27d27-0d48-4673-b9c3-76458ddae2a3"/>
<textElement>
<font size="16" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Copia "+$F{VIGENCIA}]]></textFieldExpression>
</textField>
<textField pattern="dd/MMMMM/yyyy">
<reportElement x="91" y="332" width="380" height="170" uuid="1b0f23cc-a19b-4e48-b59b-d05c3a804a8c"/>
<textElement textAlignment="Justified">
<font size="12"/>
</textElement>
<textFieldExpression><![CDATA["El Conservador de Bienes Raíces de Temuco certifica que la inscripción de fojas "+$F{FOJAS}+" número "+$F{NUMEROTITULO}+" correspondiente al Registro de Propiedad del año "+$F{ANOTITULO}+" , adjunta al presente documento, está conforme con su original y se encuentra vigente al día "+$F{FECHA}+"."+"\n\nLos derechos registrales correspondientes a esta actuación ascienden a la suma de \$ "+$F{PRECIO}+".-"]]></textFieldExpression>
</textField>
<textField pattern="dd MMMMM yyyy">
<reportElement x="143" y="521" width="137" height="20" uuid="a315d92d-94a6-41a8-b764-78f76fe590b7"/>
<textElement>
<font size="12"/>
</textElement>
<textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="91" y="520" width="60" height="20" uuid="4f6aa279-5ee1-4d92-b661-9ecd51f89384"/>
<textElement>
<font size="12"/>
</textElement>
<text><![CDATA[Temuco, ]]></text>
</staticText>
<image>
<reportElement x="390" y="561" width="91" height="86" uuid="ce857035-b39f-473d-a6e2-3b36aadb6028"/>
<imageExpression><![CDATA["C:\\Users\\Fernando\\Desktop\\Timbre_chico.png"]]></imageExpression>
</image>
<image>
<reportElement x="228" y="540" width="216" height="127" uuid="7fbdb127-6008-4c9a-a3b9-2e6b96c9cc66"/>
<imageExpression><![CDATA["C:\\Users\\Fernando\\Desktop\\firma_htoro.png"]]></imageExpression>
</image>
<componentElement>
<reportElement isPrintRepeatedValues="false" x="45" y="700" width="300" height="39" uuid="0430a4dc-0df9-45ef-83ac-0b5d1fae0e55">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<jr:Code128 xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<jr:codeExpression><![CDATA[$F{ANOACTUAL}.toString()+"-"+$F{ANOTITULO}.toString()+"-"+$F{FOJAS}.toString()+"-"+$F{NUMEROTITULO}.toString()+"-"+$F{BOLETA}.toString()]]></jr:codeExpression>
</jr:Code128>
</componentElement>
<textField>
<reportElement x="65" y="689" width="200" height="19" uuid="e3e5c7a6-44f9-407d-ac01-3a60796f1055"/>
<textElement>
<font fontName="SansSerif" size="8"/>
</textElement>
<textFieldExpression><![CDATA["Código de verificación: "+$F{COD_VERIFICACION}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band splitType="Stretch"/>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>
一切都很好,但这:我找不到一个方法,以PDF文件保存报告预览。
请问有人能帮我吗??我真的找了很多...却找不到答案...
提前感谢!!!
private void streamPdfReport(OutputStream out, HttpServletResponse response, String reportName, JasperPrint jasperPrint) throws JRException {
logger.fine("Executing streamReport...");
response.reset();
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "attachment; filename=" + reportName + ".pdf");
// work-around for IE bug, where Adobe Reader would put up an error message:
// "There was an error opening this document. This file cannot be found."
response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
JasperExportManager.exportReportToPdfStream(jasperPrint, out);
}
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
在适配器中 Holder.NameExam2.SetOnClickListener(新建View.OnClickListener(){ 成碎片 @覆盖公共视图onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){ 它在getString()中调用空指针异常。如何解决。
> 从创建的片段中更新,将新数据设置为adapter,然后调用;但没有奏效。 像其他人一样创建一个新适配器,它对他们起作用,但对我没有任何改变: 在中创建一个更新数据的方法,如下所示: 问题是gridView的布局如下所示: 然后我只是删除了并将作为父布局。
试图弄清楚更新的适配器有什么问题。 在我得到一个新的产品列表后,我尝试: > 从创建的片段中更新,将新数据设置到adapter,然后调用;但没有奏效。 像其他人一样创建一个新适配器,它对他们有效,但对我没有任何改变: 在中创建一个更新数据的方法,如下所示: 然后每当我想要更新数据列表时,我就调用这个方法;但没有奏效。 检查是否可以以任何方式修改recyclerView,并且我尝试至少删除一个项目:
问题内容: 我将数据从SQL获取到具有Fill的数据集。它只是一个具有两列(CategoryId(int)和CategoryName(varchar))的表。 当我在填充方法后查看数据集时,CategoryId Columns似乎是正确的。但是在CategoryName中,我有一个 System.Data.StrongTypingExceptio n。 那是什么意思呢? 有任何想法吗? 问题答案: