title: JRCsvExporter generates csv with blank first line
body: <p>I have a Java code which generates csv file using <strong><a href="http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/export/JRCsvExporter.html" rel="nofollow noreferrer">JRCsvExporter</a></strong> class. For some reason, it adds blank line in the top. When open in text editor it looks like this:</p>
  <p><a href="https://i.stack.imgur.com/8dPgW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8dPgW.png" alt="csv in text editor" /></a></p>
  <p>And when open in Excel it looks like this:</p>
  <p><a href="https://i.stack.imgur.com/EBpfl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EBpfl.png" alt="csv in excel" /></a></p>
  <p>The issue is due the double quotes the file begins with. When I remove those, it will appear as expected. Yet, I am note sure why those quotes generated, for what reason they good for, and how I removed them safely.</p>
  <p>The code is:</p>
  <pre><code>reportOutputName = generateReportOutputName(&quot;.csv&quot;);
  JRCsvExporter exporter = new JRCsvExporter();
  exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
  PrintStream ps = new PrintStream(new FileOutputStream(reportOutputName), true, &quot;UTF-8&quot;);
  addBOMToStream(ps);
  exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ps);
  exporter.setParameter(JRCsvExporterParameter.FIELD_DELIMITER, &quot;,&quot;);
  exporter.setParameter(JRCsvExporterParameter.RECORD_DELIMITER, System.getProperty(&quot;line.separator&quot;));
  exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, &quot;UTF-8&quot;);
  exporter.exportReport();
  </code></pre>
  <p><strong>Edit:</strong>
  The relevant part of .jrxml is:
  How can I make JRCsvExporter ignore  element when creating the csv file?</p>
  <pre><code>        &lt;title&gt;
              &lt;band height=&quot;610&quot;  isSplitAllowed=&quot;true&quot; &gt;
                  &lt;image  scaleImage=&quot;Clip&quot; vAlign=&quot;Middle&quot; hAlign=&quot;Right&quot; evaluationTime=&quot;Now&quot; hyperlinkType=&quot;None&quot;  hyperlinkTarget=&quot;Self&quot; &gt;
                      &lt;reportElement
                          x=&quot;0&quot;
                          y=&quot;5&quot;
                          width=&quot;945&quot;
                          height=&quot;40&quot;
                          key=&quot;image-1&quot;/&gt;
                      &lt;box&gt;                   &lt;topPen lineWidth=&quot;0.0&quot; lineStyle=&quot;Solid&quot; lineColor=&quot;#000000&quot;/&gt;
                      &lt;leftPen lineWidth=&quot;0.0&quot; lineStyle=&quot;Solid&quot; lineColor=&quot;#000000&quot;/&gt;
                      &lt;bottomPen lineWidth=&quot;0.0&quot; lineColor=&quot;#000000&quot;/&gt;
                      &lt;rightPen lineWidth=&quot;0.0&quot; lineStyle=&quot;Solid&quot; lineColor=&quot;#000000&quot;/&gt;
  &lt;/box&gt;
                      &lt;graphicElement stretchType=&quot;NoStretch&quot;/&gt;
                      &lt;imageExpression class=&quot;java.lang.String&quot;&gt;&lt;![CDATA[&quot;etc/report/jasper/img/TopBanner_Report.png&quot;]]&gt;&lt;/imageExpression&gt;
                  &lt;/image&gt;
                  &lt;textField isStretchWithOverflow=&quot;false&quot; pattern=&quot;&quot; isBlankWhenNull=&quot;false&quot; evaluationTime=&quot;Now&quot; hyperlinkType=&quot;None&quot;  hyperlinkTarget=&quot;Self&quot; &gt;
                      &lt;reportElement
                          mode=&quot;Transparent&quot;
                          x=&quot;0&quot;
                          y=&quot;5&quot;
                          width=&quot;945&quot;
                          height=&quot;40&quot;
                          forecolor=&quot;#FFFFFF&quot;
                          backcolor=&quot;#FFFFFF&quot;
                          key=&quot;textField-51&quot;&gt;
                              &lt;printWhenExpression&gt;&lt;![CDATA[new Boolean(!(($P{is_excel}).booleanValue()))]]&gt;&lt;/printWhenExpression&gt;
                          &lt;/reportElement&gt;
                      &lt;box leftPadding=&quot;10&quot;&gt;                  &lt;topPen lineWidth=&quot;0.0&quot; lineStyle=&quot;Solid&quot; lineColor=&quot;#E8D59C&quot;/&gt;
                      &lt;leftPen lineWidth=&quot;0.0&quot; lineStyle=&quot;Solid&quot; lineColor=&quot;#E8D59C&quot;/&gt;
                      &lt;bottomPen lineWidth=&quot;0.0&quot; lineColor=&quot;#E8D59C&quot;/&gt;
                      &lt;rightPen lineWidth=&quot;0.0&quot; lineStyle=&quot;Solid&quot; lineColor=&quot;#E8D59C&quot;/&gt;
  &lt;/box&gt;
                      &lt;textElement verticalAlignment=&quot;Middle&quot;&gt;
                          &lt;font fontName=&quot;Times-Roman&quot; pdfFontName=&quot;etc/report/jasper/fonts/ARIALUNI.TTF&quot; size=&quot;14&quot; isBold=&quot;false&quot; isPdfEmbedded =&quot;true&quot; pdfEncoding =&quot;Identity-H&quot;/&gt;
                      &lt;/textElement&gt;
                  &lt;textFieldExpression   class=&quot;java.lang.String&quot;&gt;&lt;![CDATA[$P{report_name}]]&gt;&lt;/textFieldExpression&gt;
                  &lt;/textField&gt;
                  &lt;textField isStretchWithOverflow=&quot;true&quot; isBlankWhenNull=&quot;false&quot; evaluationTime=&quot;Now&quot; hyperlinkType=&quot;None&quot;  hyperlinkTarget=&quot;Self&quot; &gt;
                      &lt;reportElement
                          mode=&quot;Opaque&quot;
                          x=&quot;0&quot;
                          y=&quot;60&quot;
                          width=&quot;945&quot;
                          height=&quot;25&quot;
                          forecolor=&quot;#000000&quot;
                          backcolor=&quot;#B8CFF2&quot;
                          key=&quot;textField-52&quot;
                          isRemoveLineWhenBlank=&quot;true&quot;&gt;
                              &lt;printWhenExpression&gt;&lt;![CDATA[new Boolean(!(($P{is_excel}).booleanValue()))]]&gt;&lt;/printWhenExpression&gt;
                          &lt;/reportElement&gt;
                      &lt;box leftPadding=&quot;10&quot;&gt;                  &lt;topPen lineWidth=&quot;0.0&quot; lineStyle=&quot;Solid&quot; lineColor=&quot;#B2E66F&quot;/&gt;
                      &lt;leftPen lineWidth=&quot;0.0&quot; lineStyle=&quot;Solid&quot; lineColor=&quot;#B2E66F&quot;/&gt;
                      &lt;bottomPen lineWidth=&quot;0.0&quot; lineColor=&quot;#B2E66F&quot;/&gt;
                      &lt;rightPen lineWidth=&quot;0.0&quot; lineStyle=&quot;Solid&quot; lineColor=&quot;#B2E66F&quot;/&gt;
  &lt;/box&gt;
                      &lt;textElement verticalAlignment=&quot;Middle&quot;&gt;
                          &lt;font fontName=&quot;Arial Unicode MS&quot; pdfFontName=&quot;etc/report/jasper/fonts/ARIALUNI.TTF&quot; size=&quot;12&quot; isBold=&quot;true&quot; isPdfEmbedded =&quot;true&quot; pdfEncoding =&quot;Identity-H&quot;/&gt;
                      &lt;/textElement&gt;
                  &lt;textFieldExpression   class=&quot;java.lang.String&quot;&gt;&lt;![CDATA[&quot;Report Details&quot;]]&gt;&lt;/textFieldExpression&gt;
                  &lt;/textField&gt;
                  &lt;rectangle radius=&quot;0&quot; &gt;
                      &lt;reportElement
                          mode=&quot;Opaque&quot;
                          x=&quot;0&quot;
                          y=&quot;85&quot;
                          width=&quot;945&quot;
                          height=&quot;505&quot;
                          forecolor=&quot;#535353&quot;
                          backcolor=&quot;#ECECEC&quot;
                          key=&quot;rectangle-1&quot;
                          stretchType=&quot;RelativeToTallestObject&quot;/&gt;
                      &lt;graphicElement stretchType=&quot;RelativeToTallestObject&quot;&gt;
                      &lt;pen lineWidth=&quot;0.0&quot; lineStyle=&quot;Solid&quot;/&gt;
  &lt;/graphicElement&gt;
                  &lt;/rectangle&gt;
                  &lt;textField isStretchWithOverflow=&quot;true&quot; isBlankWhenNull=&quot;false&quot; evaluationTime=&quot;Now&quot; hyperlinkType=&quot;None&quot;  hyperlinkTarget=&quot;Self&quot; &gt;
                      &lt;reportElement
                          mode=&quot;Opaque&quot;
                          x=&quot;0&quot;
                          y=&quot;110&quot;
                          width=&quot;945&quot;
                          height=&quot;25&quot;
                          forecolor=&quot;#535353&quot;
                          backcolor=&quot;#EBEDEF&quot;
                          key=&quot;textField-48&quot;
                          isRemoveLineWhenBlank=&quot;true&quot;&gt;
                              &lt;printWhenExpression&gt;&lt;![CDATA[new Boolean(!(($P{is_excel}).booleanValue()))]]&gt;&lt;/printWhenExpression&gt;
                          &lt;/reportElement&gt;
                      &lt;box leftPadding=&quot;10&quot;&gt;                  &lt;topPen lineWidth=&quot;0.0&quot; lineStyle=&quot;Solid&quot; lineColor=&quot;#E8D59C&quot;/&gt;
                      &lt;leftPen lineWidth=&quot;0.0&quot; lineStyle=&quot;Solid&quot; lineColor=&quot;#C1CDD8&quot;/&gt;
                      &lt;bottomPen lineWidth=&quot;0.0&quot; lineColor=&quot;#E8D59C&quot;/&gt;
                      &lt;rightPen lineWidth=&quot;0.0&quot; lineStyle=&quot;Solid&quot; lineColor=&quot;#C1CDD8&quot;/&gt;
  &lt;/box&gt;
                      &lt;textElement verticalAlignment=&quot;Middle&quot;&gt;
                          &lt;font fontName=&quot;Arial Unicode MS&quot; pdfFontName=&quot;etc/report/jasper/fonts/ARIALUNI.TTF&quot; size=&quot;12&quot; isBold=&quot;true&quot; isPdfEmbedded =&quot;true&quot; pdfEncoding =&quot;Identity-H&quot;/&gt;
                      &lt;/textElement&gt;
                  &lt;textFieldExpression   class=&quot;java.lang.String&quot;&gt;&lt;![CDATA[&quot;Generated By: &quot;+$P{report_generatedby}]]&gt;&lt;/textFieldExpression&gt;
                  &lt;/textField&gt;
                  &lt;textField isStretchWithOverflow=&quot;true&quot; pattern=&quot;&quot; isBlankWhenNull=&quot;false&quot; evaluationTime=&quot;Now&quot; hyperlinkType=&quot;None&quot;  hyperlinkTarget=&quot;Self&quot; &gt;
                      &lt;reportElement
                          mode=&quot;Opaque&quot;
                          x=&quot;0&quot;
                          y=&quot;85&quot;
                          width=&quot;945&quot;
                          height=&quot;25&quot;
                          forecolor=&quot;#535353&quot;
                          backcolor=&quot;#EBEDEF&quot;
                          key=&quot;textField-46&quot;
                          isRemoveLineWhenBlank=&quot;true&quot;&gt;
                              &lt;printWhenExpression&gt;&lt;![CDATA[new Boolean(!(($P{is_excel}).booleanValue()))]]&gt;&lt;/printWhenExpression&gt;
                          &lt;/reportElement&gt;
                      &lt;box leftPadding=&quot;10&quot;&gt;                  &lt;topPen lineWidth=&quot;0.0&quot; lineStyle=&quot;Solid&quot; lineColor=&quot;#C1CDD8&quot;/&gt;
                      &lt;leftPen lineWidth=&quot;0.0&quot; lineStyle=&quot;Solid&quot; lineColor=&quot;#C1CDD8&quot;/&gt;
                      &lt;bottomPen lineWidth=&quot;0.0&quot; lineColor=&quot;#E8D59C&quot;/&gt;
                      &lt;rightPen lineWidth=&quot;0.0&quot; lineStyle=&quot;Solid&quot; lineColor=&quot;#C1CDD8&quot;/&gt;
  &lt;/box&gt;
                      &lt;textElement verticalAlignment=&quot;Middle&quot;&gt;
                          &lt;font fontName=&quot;Arial Unicode MS&quot; pdfFontName=&quot;etc/report/jasper/fonts/ARIALUNI.TTF&quot; size=&quot;12&quot; isBold=&quot;true&quot; isPdfEmbedded =&quot;true&quot; pdfEncoding =&quot;Identity-H&quot; isStrikeThrough=&quot;false&quot; /&gt;
                      &lt;/textElement&gt;
                  &lt;textFieldExpression   class=&quot;java.lang.String&quot;&gt;&lt;![CDATA[&quot;Hosts: '&quot;+$P{ip_range_text}+&quot;'&quot;]]&gt;&lt;/textFieldExpression&gt;
                  &lt;/textField&gt;
                  &lt;textField isStretchWithOverflow=&quot;true&quot; isBlankWhenNull=&quot;false&quot; evaluationTime=&quot;Now&quot; hyperlinkType=&quot;None&quot;  hyperlinkTarget=&quot;Self&quot; &gt;
                      &lt;reportElement
                          mode=&quot;Opaque&quot;
                          x=&quot;0&quot;
                          y=&quot;135&quot;
                          width=&quot;945&quot;
                          height=&quot;25&quot;
                          forecolor=&quot;#535353&quot;
                          backcolor=&quot;#EBEDEF&quot;
                          key=&quot;textField-49&quot;
                          isRemoveLineWhenBlank=&quot;true&quot;&gt;
                              &lt;printWhenExpression&gt;&lt;![CDATA[new Boolean(!(($P{is_excel}).booleanValue()))]]&gt;&lt;/printWhenExpression&gt;
                          &lt;/reportElement&gt;
                      &lt;box leftPadding=&quot;10&quot; bottomPadding=&quot;5&quot;&gt;                    &lt;topPen lineWidth=&quot;0.0&quot; lineStyle=&quot;Solid&quot; lineColor=&quot;#E8D59C&quot;/&gt;
                      &lt;leftPen lineWidth=&quot;0.0&quot; lineStyle=&quot;Solid&quot; lineColor=&quot;#C1CDD8&quot;/&gt;
                      &lt;bottomPen lineWidth=&quot;0.0&quot; lineColor=&quot;#E8D59C&quot;/&gt;
                      &lt;rightPen lineWidth=&quot;0.0&quot; lineStyle=&quot;Solid&quot; lineColor=&quot;#C1CDD8&quot;/&gt;
  &lt;/box&gt;
                      &lt;textElement verticalAlignment=&quot;Middle&quot;&gt;
                          &lt;font fontName=&quot;Arial Unicode MS&quot; pdfFontName=&quot;etc/report/jasper/fonts/ARIALUNI.TTF&quot; size=&quot;12&quot; isBold=&quot;true&quot; isPdfEmbedded =&quot;true&quot; pdfEncoding =&quot;Identity-H&quot;/&gt;
                      &lt;/textElement&gt;
                  &lt;textFieldExpression   class=&quot;java.lang.String&quot;&gt;&lt;![CDATA[&quot;Generated At: &quot;+(new java.util.Date()).toString()]]&gt;&lt;/textFieldExpression&gt;
                  &lt;/textField&gt;
                  &lt;textField isStretchWithOverflow=&quot;true&quot; pattern=&quot;&quot; isBlankWhenNull=&quot;false&quot; evaluationTime=&quot;Now&quot; hyperlinkType=&quot;None&quot;  hyperlinkTarget=&quot;Self&quot; &gt;
                      &lt;reportElement
                          mode=&quot;Opaque&quot;
                          x=&quot;0&quot;
                          y=&quot;160&quot;
                          width=&quot;945&quot;
                          height=&quot;100&quot;
                          forecolor=&quot;#535353&quot;
                          backcolor=&quot;#EBEDEF&quot;
                          key=&quot;textField-47&quot;
                          isRemoveLineWhenBlank=&quot;true&quot;&gt;
                              &lt;printWhenExpression&gt;&lt;![CDATA[new Boolean(!(($P{is_excel}).booleanValue()))]]&gt;&lt;/printWhenExpression&gt;
                          &lt;/reportElement&gt;
                      &lt;box leftPadding=&quot;10&quot; rightPadding=&quot;10&quot; bottomPadding=&quot;5&quot;&gt;                  &lt;topPen lineWidth=&quot;0.0&quot; lineStyle=&quot;Solid&quot; lineColor=&quot;#C1CDD8&quot;/&gt;
                      &lt;leftPen lineWidth=&quot;0.0&quot; lineStyle=&quot;Solid&quot; lineColor=&quot;#C1CDD8&quot;/&gt;
                      &lt;bottomPen lineWidth=&quot;0.0&quot; lineColor=&quot;#C1CDD8&quot;/&gt;
                      &lt;rightPen lineWidth=&quot;0.0&quot; lineStyle=&quot;Solid&quot; lineColor=&quot;#C1CDD8&quot;/&gt;
  &lt;/box&gt;
                      &lt;textElement textAlignment=&quot;Justified&quot; verticalAlignment=&quot;Middle&quot;&gt;
                          &lt;font fontName=&quot;Arial Unicode MS&quot; pdfFontName=&quot;etc/report/jasper/fonts/ARIALUNI.TTF&quot; size=&quot;12&quot; isBold=&quot;true&quot; isPdfEmbedded =&quot;true&quot; pdfEncoding =&quot;Identity-H&quot;/&gt;
                      &lt;/textElement&gt;
                  &lt;textFieldExpression   class=&quot;java.lang.String&quot;&gt;&lt;![CDATA[$P{report_description}]]&gt;&lt;/textFieldExpression&gt;
                  &lt;/textField&gt;
                  &lt;textField isStretchWithOverflow=&quot;false&quot; isBlankWhenNull=&quot;false&quot; evaluationTime=&quot;Report&quot; hyperlinkType=&quot;None&quot;  hyperlinkTarget=&quot;Self&quot; &gt;
                      &lt;reportElement
                          mode=&quot;Transparent&quot;
                          x=&quot;0&quot;
                          y=&quot;260&quot;
                          width=&quot;945&quot;
                          height=&quot;330&quot;
                          forecolor=&quot;#535353&quot;
                          backcolor=&quot;#EBEDEF&quot;
                          key=&quot;notice-text&quot;/&gt;
                      &lt;box leftPadding=&quot;10&quot; rightPadding=&quot;10&quot; bottomPadding=&quot;5&quot;&gt;&lt;/box&gt;
                      &lt;textElement textAlignment=&quot;Justified&quot; verticalAlignment=&quot;Middle&quot; markup=&quot;html&quot;&gt;
                          &lt;font fontName=&quot;Arial Unicode MS&quot; pdfFontName=&quot;etc/report/jasper/fonts/ARIALUNI.TTF&quot; size=&quot;12&quot; isBold=&quot;true&quot; isPdfEmbedded =&quot;true&quot; pdfEncoding =&quot;Identity-H&quot;/&gt;
                      &lt;/textElement&gt;
                  &lt;textFieldExpression   class=&quot;java.lang.String&quot;&gt;&lt;![CDATA[$P{notice_text}+&quot;&lt;p&gt;&lt;span style='color:#D8000C'&gt;&quot;+$V{missingDataWrapper}+&quot;&lt;/span&gt;&lt;/p&gt;&quot;]]&gt;&lt;/textFieldExpression&gt;
                  &lt;/textField&gt;
              &lt;/band&gt;
          &lt;/title&gt;
  </code></pre>