<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Write Flowfile content into Excel (or xls) file by Groovy (and Ivy) in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Write-Flowfile-content-into-Excel-or-xls-file-by-Groovy-and/m-p/359265#M238059</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you can use after you received the result from your SQL-Database the ConvertRecord Processor to convert from Avro (Reader) to CSV (Writer). That should handle your question to do it without some Script.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Greetings&lt;/P&gt;</description>
    <pubDate>Fri, 09 Dec 2022 16:09:12 GMT</pubDate>
    <dc:creator>Faerballert</dc:creator>
    <dc:date>2022-12-09T16:09:12Z</dc:date>
    <item>
      <title>Write Flowfile content into Excel (or xls) file by Groovy (and Ivy)</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Write-Flowfile-content-into-Excel-or-xls-file-by-Groovy-and/m-p/359241#M238057</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to extract data from a SQL query into Excel file (or xls)&lt;/P&gt;&lt;P&gt;Is it possible to do it by Groovy script ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2022 15:24:58 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Write-Flowfile-content-into-Excel-or-xls-file-by-Groovy-and/m-p/359241#M238057</guid>
      <dc:creator>yamaga</dc:creator>
      <dc:date>2022-12-09T15:24:58Z</dc:date>
    </item>
    <item>
      <title>Re: Write Flowfile content into Excel (or xls) file by Groovy (and Ivy)</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Write-Flowfile-content-into-Excel-or-xls-file-by-Groovy-and/m-p/359265#M238059</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you can use after you received the result from your SQL-Database the ConvertRecord Processor to convert from Avro (Reader) to CSV (Writer). That should handle your question to do it without some Script.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Greetings&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2022 16:09:12 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Write-Flowfile-content-into-Excel-or-xls-file-by-Groovy-and/m-p/359265#M238059</guid>
      <dc:creator>Faerballert</dc:creator>
      <dc:date>2022-12-09T16:09:12Z</dc:date>
    </item>
    <item>
      <title>Re: Write Flowfile content into Excel (or xls) file by Groovy (and Ivy)</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Write-Flowfile-content-into-Excel-or-xls-file-by-Groovy-and/m-p/359267#M238061</link>
      <description>&lt;P&gt;My input should be XLS file not csv&lt;/P&gt;&lt;P&gt;I think about Groovy script but did not find anything about it&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2022 16:24:20 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Write-Flowfile-content-into-Excel-or-xls-file-by-Groovy-and/m-p/359267#M238061</guid>
      <dc:creator>yamaga</dc:creator>
      <dc:date>2022-12-09T16:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: Write Flowfile content into Excel (or xls) file by Groovy (and Ivy)</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Write-Flowfile-content-into-Excel-or-xls-file-by-Groovy-and/m-p/359268#M238062</link>
      <description>&lt;P&gt;Sorry, I misread &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But after convertion to csv you could check out topics like&amp;nbsp;&lt;A href="https://community.cloudera.com/t5/Support-Questions/how-to-convert-CSV-to-excel-using-apache-nifi/td-p/332089" target="_blank"&gt;https://community.cloudera.com/t5/Support-Questions/how-to-convert-CSV-to-excel-using-apache-nifi/td-p/332089&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2022 16:34:51 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Write-Flowfile-content-into-Excel-or-xls-file-by-Groovy-and/m-p/359268#M238062</guid>
      <dc:creator>Faerballert</dc:creator>
      <dc:date>2022-12-09T16:34:51Z</dc:date>
    </item>
    <item>
      <title>Re: Write Flowfile content into Excel (or xls) file by Groovy (and Ivy)</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Write-Flowfile-content-into-Excel-or-xls-file-by-Groovy-and/m-p/359994#M238259</link>
      <description>&lt;P&gt;Any ideas please ?&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2022 22:03:11 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Write-Flowfile-content-into-Excel-or-xls-file-by-Groovy-and/m-p/359994#M238259</guid>
      <dc:creator>yamaga</dc:creator>
      <dc:date>2022-12-21T22:03:11Z</dc:date>
    </item>
    <item>
      <title>Re: Write Flowfile content into Excel (or xls) file by Groovy (and Ivy)</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Write-Flowfile-content-into-Excel-or-xls-file-by-Groovy-and/m-p/360496#M238412</link>
      <description>&lt;P&gt;I found a solution, this is the script:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class="hljs-meta"&gt;@Grapes(@Grab(group='org.apache.poi', module='poi-ooxml', version='3.9'))&lt;/SPAN&gt;
&lt;SPAN class="hljs-keyword"&gt;import&lt;/SPAN&gt; com.opencsv.CSVReader
&lt;SPAN class="hljs-meta"&gt;@Grapes(@Grab(group='com.opencsv', module='opencsv', version='4.2'))&lt;/SPAN&gt;
&lt;SPAN class="hljs-keyword"&gt;import&lt;/SPAN&gt; org.apache.poi.ss.usermodel.*
&lt;SPAN class="hljs-keyword"&gt;import&lt;/SPAN&gt; org.apache.poi.xssf.streaming.*
&lt;SPAN class="hljs-keyword"&gt;import&lt;/SPAN&gt; org.apache.poi.hssf.usermodel.*
&lt;SPAN class="hljs-keyword"&gt;import&lt;/SPAN&gt; org.apache.poi.xssf.usermodel.*
&lt;SPAN class="hljs-keyword"&gt;import&lt;/SPAN&gt; org.apache.poi.ss.util.*
&lt;SPAN class="hljs-keyword"&gt;import&lt;/SPAN&gt; org.apache.poi.ss.usermodel.*
&lt;SPAN class="hljs-keyword"&gt;import&lt;/SPAN&gt; org.apache.poi.hssf.extractor.*
&lt;SPAN class="hljs-keyword"&gt;import&lt;/SPAN&gt; java.nio.charset.*
&lt;SPAN class="hljs-keyword"&gt;import&lt;/SPAN&gt; java.io.*
&lt;SPAN class="hljs-keyword"&gt;import&lt;/SPAN&gt; org.apache.commons.io.IOUtils

&lt;SPAN class="hljs-type"&gt;def&lt;/SPAN&gt; &lt;SPAN class="hljs-variable"&gt;flowFile&lt;/SPAN&gt; &lt;SPAN class="hljs-operator"&gt;=&lt;/SPAN&gt; session.get()
&lt;SPAN class="hljs-type"&gt;def&lt;/SPAN&gt; &lt;SPAN class="hljs-variable"&gt;date&lt;/SPAN&gt; &lt;SPAN class="hljs-operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="hljs-keyword"&gt;new&lt;/SPAN&gt; &lt;SPAN class="hljs-title class_"&gt;Date&lt;/SPAN&gt;()

&lt;SPAN class="hljs-keyword"&gt;if&lt;/SPAN&gt;(!flowFile) &lt;SPAN class="hljs-type"&gt;return&lt;/SPAN&gt;


&lt;SPAN class="hljs-variable"&gt;flowFile&lt;/SPAN&gt; &lt;SPAN class="hljs-operator"&gt;=&lt;/SPAN&gt; session.write(flowFile, {inputStream, outputStream -&amp;gt;
        &lt;SPAN class="hljs-type"&gt;SXSSFSheet&lt;/SPAN&gt; &lt;SPAN class="hljs-variable"&gt;sheet1&lt;/SPAN&gt; &lt;SPAN class="hljs-operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="hljs-literal"&gt;null&lt;/SPAN&gt;;
        &lt;SPAN class="hljs-type"&gt;CSVReader&lt;/SPAN&gt; &lt;SPAN class="hljs-variable"&gt;reader&lt;/SPAN&gt; &lt;SPAN class="hljs-operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="hljs-literal"&gt;null&lt;/SPAN&gt;;
        &lt;SPAN class="hljs-type"&gt;Workbook&lt;/SPAN&gt; &lt;SPAN class="hljs-variable"&gt;wb&lt;/SPAN&gt; &lt;SPAN class="hljs-operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="hljs-literal"&gt;null&lt;/SPAN&gt;;
        &lt;SPAN class="hljs-type"&gt;String&lt;/SPAN&gt; &lt;SPAN class="hljs-variable"&gt;generatedXlsFilePath&lt;/SPAN&gt; &lt;SPAN class="hljs-operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"/home/"&lt;/SPAN&gt;;
        &lt;SPAN class="hljs-type"&gt;FileOutputStream&lt;/SPAN&gt; &lt;SPAN class="hljs-variable"&gt;fileOutputStream&lt;/SPAN&gt; &lt;SPAN class="hljs-operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="hljs-literal"&gt;null&lt;/SPAN&gt;;
  
  &lt;SPAN class="hljs-type"&gt;def&lt;/SPAN&gt; &lt;SPAN class="hljs-variable"&gt;filename&lt;/SPAN&gt; &lt;SPAN class="hljs-operator"&gt;=&lt;/SPAN&gt; flowFile.getAttribute(&lt;SPAN class="hljs-string"&gt;'filename'&lt;/SPAN&gt;)
  &lt;SPAN class="hljs-type"&gt;def&lt;/SPAN&gt; &lt;SPAN class="hljs-variable"&gt;path&lt;/SPAN&gt; &lt;SPAN class="hljs-operator"&gt;=&lt;/SPAN&gt; flowFile.getAttribute(&lt;SPAN class="hljs-string"&gt;'path'&lt;/SPAN&gt;)
  
            &lt;SPAN class="hljs-type"&gt;def&lt;/SPAN&gt; &lt;SPAN class="hljs-variable"&gt;nextLine&lt;/SPAN&gt; &lt;SPAN class="hljs-operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;''&lt;/SPAN&gt;
            reader = &lt;SPAN class="hljs-keyword"&gt;new&lt;/SPAN&gt; &lt;SPAN class="hljs-title class_"&gt;CSVReader&lt;/SPAN&gt;(&lt;SPAN class="hljs-keyword"&gt;new&lt;/SPAN&gt; &lt;SPAN class="hljs-title class_"&gt;FileReader&lt;/SPAN&gt;(path+filename), &lt;SPAN class="hljs-string"&gt;','&lt;/SPAN&gt;);
 
 &lt;SPAN class="hljs-comment"&gt;//Workbook wb = WorkbookFactory.create(inputStream,);&lt;/SPAN&gt;
 &lt;SPAN class="hljs-comment"&gt;//Sheet sheet1 = wb.createSheet("Feuille");&lt;/SPAN&gt;
 
            wb = &lt;SPAN class="hljs-keyword"&gt;new&lt;/SPAN&gt; &lt;SPAN class="hljs-title class_"&gt;SXSSFWorkbook&lt;/SPAN&gt;(inputStream);
            sheet1 = (SXSSFSheet) wb.createSheet(&lt;SPAN class="hljs-string"&gt;'Sheet'&lt;/SPAN&gt;);
 
            &lt;SPAN class="hljs-type"&gt;def&lt;/SPAN&gt; &lt;SPAN class="hljs-variable"&gt;rowNum&lt;/SPAN&gt; &lt;SPAN class="hljs-operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;;
            &lt;SPAN class="hljs-keyword"&gt;while&lt;/SPAN&gt;((nextLine = reader.readNext()) != &lt;SPAN class="hljs-literal"&gt;null&lt;/SPAN&gt;) {
                &lt;SPAN class="hljs-type"&gt;Row&lt;/SPAN&gt; &lt;SPAN class="hljs-variable"&gt;currentRow&lt;/SPAN&gt; &lt;SPAN class="hljs-operator"&gt;=&lt;/SPAN&gt; sheet1.createRow(rowNum++);
                &lt;SPAN class="hljs-keyword"&gt;for&lt;/SPAN&gt;(&lt;SPAN class="hljs-type"&gt;int&lt;/SPAN&gt; i=&lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;; i &amp;lt; nextLine.length; i++) {
                    &lt;SPAN class="hljs-keyword"&gt;if&lt;/SPAN&gt;(NumberUtils.isDigits(nextLine[i])) {
                        currentRow.createCell(i).setCellValue(Integer.parseInt(nextLine[i]));
                    } &lt;SPAN class="hljs-keyword"&gt;else&lt;/SPAN&gt; &lt;SPAN class="hljs-keyword"&gt;if&lt;/SPAN&gt; (NumberUtils.isNumber(nextLine[i])) {
                        currentRow.createCell(i).setCellValue(Double.parseDouble(nextLine[i]));
                    } &lt;SPAN class="hljs-keyword"&gt;else&lt;/SPAN&gt; {
                        currentRow.createCell(i).setCellValue(nextLine[i]);
                    }
                }
            }
  
 
            &lt;SPAN class="hljs-comment"&gt;//fileOutputStream = new FileOutputStream(generatedXlsFilePath.trim());&lt;/SPAN&gt;
            &lt;SPAN class="hljs-comment"&gt;//wb.write(fileOutputStream);&lt;/SPAN&gt;
            generatedXlsFilePath = generatedXlsFilePath + &lt;SPAN class="hljs-string"&gt;'SAISIE_MAGASING.XLS'&lt;/SPAN&gt;
            outputStream = &lt;SPAN class="hljs-keyword"&gt;new&lt;/SPAN&gt; &lt;SPAN class="hljs-title class_"&gt;FileOutputStream&lt;/SPAN&gt;(generatedXlsFilePath.trim());
 
            wb.write(outputStream);
            
                wb.close();
                &lt;SPAN class="hljs-comment"&gt;//fileOutputStream.close();&lt;/SPAN&gt;
                outputStream.close();
                reader.close();
                &lt;SPAN class="hljs-comment"&gt;//outputStream.close();&lt;/SPAN&gt;
                inputStream.close();
                
  
} as StreamCallback)



flowFile = session.putAttribute(flowFile, &lt;SPAN class="hljs-string"&gt;'filename'&lt;/SPAN&gt;, filename)&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Jan 2023 21:57:34 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Write-Flowfile-content-into-Excel-or-xls-file-by-Groovy-and/m-p/360496#M238412</guid>
      <dc:creator>yamaga</dc:creator>
      <dc:date>2023-01-03T21:57:34Z</dc:date>
    </item>
  </channel>
</rss>

