Jump to content

saifytdin

Members
  • Posts

    5
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

saifytdin's Achievements

  1. Problem was with decimal separator- in csv it is dot, but in java.text.DecimalFormatSymbols#decimalSeparator it is comma (came from locale a guess), so I added following code and things started working JRCsvDataSource jrCsvDataSource = new JRCsvDataSource(csvFsDataInputStream); jrCsvDataSource.setFieldDelimiter(";".charAt(0)); jrCsvDataSource.setUseFirstRowAsHeader(true); DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(); decimalFormatSymbols.setDecimalSeparator('.'); DecimalFormat decimalFormat = new DecimalFormat("0.00######################", decimalFormatSymbols); decimalFormat.setParseBigDecimal(true); jrCsvDataSource.setNumberFormat(decimalFormat);
  2. Following code in Jasper instantiates BigDecimal: public static Number net.sf.jasperreports.engine.util.FormatUtils#getFormattedNumber(NumberFormat numberFormat, String fieldValue, Class<?> valueClass) throws ParseException { if (valueClass.equals(Byte.class)) { return numberFormat.parse(fieldValue).byteValue(); } else if (valueClass.equals(Integer.class)) { return numberFormat.parse(fieldValue).intValue(); } else if (valueClass.equals(Long.class)) { return numberFormat.parse(fieldValue).longValue(); } else if (valueClass.equals(Short.class)) { return numberFormat.parse(fieldValue).shortValue(); } else if (valueClass.equals(Double.class)) { return numberFormat.parse(fieldValue).doubleValue(); } else if (valueClass.equals(Float.class)) { return numberFormat.parse(fieldValue).floatValue(); } else if (valueClass.equals(BigDecimal.class)) { return new BigDecimal(numberFormat.parse(fieldValue).toString()); } else if (valueClass.equals(BigInteger.class)) { return new BigInteger(String.valueOf(numberFormat.parse(fieldValue).longValue())); } else { return valueClass.equals(Number.class) ? numberFormat.parse(fieldValue) : null; } } fieldValue is following String "111111111111111111111111111111.222222222222" but result of numberFormat.parse(fieldValue).toString() returns String without fractional part "111111111111111111111111111111" if NumberFormat instantiated this way: NumberFormat numberFormat = NumberFormat.getInstance(); DecimalFormat decimalFormat = (DecimalFormat) numberFormat; decimalFormat.setParseBigDecimal(true); And may return first 16 numbers "1111111111111111" if only NumberFormat passed as parameter. There is very complicated logic in java.text.NumberFormat#parse(java.lang.String, java.text.ParsePosition) responsible for parsing fieldValue that comes as String. Many Thanks for any ideas how to instantiate NumberFormat correct way, so the fractional won't be missed in numberFormat.parse(fieldValue).toString()..
  3. Any ideas please why JRPrintText returns 0 instead of all digits starting from 18th one if field declared in JasperReport as BigDecimal while value in CSV file that was used to fill the field from contains 30 digits before decimal and 9 digits after? log.info("File contents:"); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(hdfsFileSystem.open(hdfsLocatedFileStatus.getPath()))); String line; while ((line = bufferedReader.readLine()) != null) { log.info(line); } log.info("JasperReports printElement values:"); for(JRPrintPage jrPrintPage : jasperPrint.getPages()){ for(JRPrintElement jrPrintElement : jrPrintPage.getElements()){ if (jrPrintElement instanceof JRPrintText){ JRPrintText jrPrintText = (JRPrintText) jrPrintElement; log.info("Text Element Value: " + jrPrintText.getFullText()); } } } File contents: ;SHAREHOLDER_STOCK_QUANTITY; ;123456789012345678901234567890.123456789; JasperReports printElement values: Text Element Value: 123456789012345680000000000000.00
  4. Created report based on csv data adapter. Added to report table element. Table element uses Dataset (Dataset Run) which was created using main csv data adapter. Dataset property "Use a JRDatasource expression" is set to $P{REPORT_DATA_SOURCE} "Parameter Map" is set to $P{REPORT_PARAMETERS_MAP} Table element in Jrxml: <componentElement> <reportElement x="1420" y="20" width="250" height="50" uuid="0e621b52-2246-4e00-916c-4d0b91f0b727"> <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/> <property name="com.jaspersoft.studio.table.style.table_header" value="Table 2_TH"/> <property name="com.jaspersoft.studio.table.style.column_header" value="Table 2_CH"/> <property name="com.jaspersoft.studio.table.style.detail" value="Table 2_TD"/> <property name="com.jaspersoft.studio.components.autoresize.proportional" value="true"/> </reportElement> <jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd"> <datasetRun subDataset="SHAREHOLDER_STOCK_CATEGORY_DATASET" uuid="25d6de91-b664-49e2-b950-9ef0491cea72"> <parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]></parametersMapExpression> <dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression> </datasetRun> <jr:column width="119" uuid="a8bbf8cd-009f-41f2-9993-afb9ce0ad1eb"> <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/> <jr:groupFooter groupName="SHAREHOLDER_STOCK_CATEGORY_GROUP"> <jr:cell height="30" rowSpan="1"> <textField> <reportElement x="0" y="0" width="119" height="30" backcolor="#FFFFFF" uuid="af6fa926-20a4-4bbe-8389-3c5fe94182a5"/> <box> <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> </box> <textElement textAlignment="Right"> <font isBold="true"/> </textElement> <textFieldExpression><![CDATA[$F{SHAREHOLDER_STOCK_CATEGORY}]]></textFieldExpression> </textField> </jr:cell> </jr:groupFooter> <jr:detailCell height="20"> <textField> <reportElement x="0" y="0" width="119" height="20" uuid="28889612-a9a0-42ca-b6d1-3a62338de5a8"/> <box> <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> </box> <textFieldExpression><![CDATA[$F{SHAREHOLDER_STOCK_CATEGORY}]]></textFieldExpression> </textField> </jr:detailCell> </jr:column> <jr:column width="131" uuid="092c0c0e-7220-4a04-aff9-e19cb74c1586"> <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/> <jr:groupFooter groupName="SHAREHOLDER_STOCK_CATEGORY_GROUP"> <jr:cell height="30" rowSpan="1"> <textField> <reportElement x="0" y="0" width="131" height="30" uuid="038cd67f-89ca-4917-b109-a69cb052c460"/> <box> <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> </box> <textElement textAlignment="Right"> <font isBold="true"/> </textElement> <textFieldExpression><![CDATA[$V{SHAREHOLDER_STOCK_QUANTITY1}]]></textFieldExpression> </textField> </jr:cell> </jr:groupFooter> <jr:detailCell style="Table 2_TD" height="20"> <textField> <reportElement mode="Transparent" x="0" y="0" width="131" height="20" uuid="45de8f2b-c8f1-4826-9e37-4a48928fae7c"/> <box> <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> </box> <textFieldExpression><![CDATA[$F{SHAREHOLDER_STOCK_QUANTITY}]]></textFieldExpression> </textField> </jr:detailCell> </jr:column> <jr:detail> <printWhenExpression><![CDATA[1==0]]></printWhenExpression> </jr:detail> </jr:table> </componentElement> When report runs in JasperReport Studio- table elements displays data perfectly fine But when I try to print same jrxml using JRXlsxExporter to XLSX this table element is empty. Any Ideas please how to fix this? Use JasperStudio 6.18.1 JasperReports dependencies in project: implementation group: 'net.sf.jasperreports', name: 'jasperreports', version: '6.18.1' implementation 'net.sf.jasperreports:jasperreports-annotation-processors:6.7.0'
×
×
  • Create New...