<?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>topic Re: How to save CSV file with custom text before headers in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-save-CSV-file-with-custom-text-before-headers/m-p/665401#M85370</link>
    <description>&lt;P&gt;You might want to look into reading the whole csv file into a text string using&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Load Text File()&lt;/P&gt;
&lt;P&gt;You can then parse the string variable for the information you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Save Text File()&lt;/P&gt;
&lt;P&gt;can then be used to write the file back to your hard drive.&lt;/P&gt;</description>
    <pubDate>Thu, 03 Aug 2023 20:32:27 GMT</pubDate>
    <dc:creator>txnelson</dc:creator>
    <dc:date>2023-08-03T20:32:27Z</dc:date>
    <item>
      <title>How to save CSV file with custom text before headers</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-save-CSV-file-with-custom-text-before-headers/m-p/665334#M85366</link>
      <description>&lt;P&gt;There is a way to import a csv file where headers start not from the first line. You just specify the on what line the headers are.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But let's say after I did something with the data table and I want to export it back to the same format, how would I do that? Let's say I have the text, and it is just one line.&lt;/P&gt;&lt;P&gt;So that this CSV in Excel looks like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2023-08-03 11_38_33-Book1 - Excel.png" style="width: 217px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/55547iDBFA0614FDF2DC8A/image-size/large?v=v2&amp;amp;px=999" role="button" title="2023-08-03 11_38_33-Book1 - Excel.png" alt="2023-08-03 11_38_33-Book1 - Excel.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;and in a Notepad it looks like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2023-08-03 11_40_14-Window.png" style="width: 296px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/55548i47DDC55FA51ED84E/image-size/large?v=v2&amp;amp;px=999" role="button" title="2023-08-03 11_40_14-Window.png" alt="2023-08-03 11_40_14-Window.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a clean way to do that purely in JSL?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;The way I'm currently trying to do this:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;The opposite operation of reading CSV file I'm doing by reading CSV as a text file into &lt;EM&gt;ex&lt;/EM&gt;, figuring out where my headers start (they can start at different places) and getting the line number as &lt;EM&gt;headersLocation&lt;/EM&gt;, then doing:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;		dtInt_ = Open(
			Char To Blob( ex ),
			Import Settings(
				End Of Line( CRLF, CR, LF ),
				End Of Field( Comma, CSV( 0 ) ),
				Strip Quotes( 1 ),
				Use Apostrophe as Quotation Mark( 0 ),
				Use Regional Settings( 0 ),
				Scan Whole File( 1 ),
				Treat empty columns as numeric( 0 ),
				CompressNumericColumns( 0 ),
				CompressCharacterColumns( 0 ),
				CompressAllowListCheck( 0 ),
				Labels( 1 ),
				Column Names Start( headersLocation ),
				Data Starts( headersLocation + 1 ),
				Lines To Read( "All" ),
				Year Rule( "20xx" )
			),
			Invisible
		);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So, my current plan is to get my processed data table into a BLOB somehow, and then just do the opposite Blob To Char() function and prepend some text to it and save it as a CSV file.&lt;/P&gt;&lt;P&gt;I'm stuck into getting data table to blob, so that I could get it to Char (which probably not the right way), or somehow get the data table to CSV format as a text (not save as a file).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alternatively, I can save it to a CSV file, then read that file back as text and prepend a line and save it again (deleting temporary CSV file) - but it seems to be a very awkward way of doing this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&amp;nbsp;&lt;/P&gt;&lt;P&gt;M.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2023 19:04:56 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-save-CSV-file-with-custom-text-before-headers/m-p/665334#M85366</guid>
      <dc:creator>miguello</dc:creator>
      <dc:date>2023-08-03T19:04:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to save CSV file with custom text before headers</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-save-CSV-file-with-custom-text-before-headers/m-p/665373#M85369</link>
      <description>&lt;P&gt;Ok, for now I solved it this way:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Current Data Table();

filePath = "C:\TEMP\test.csv";
dt &amp;lt;&amp;lt; Save(filePath);
dt_text = Load Text File(filePath);
out = "Custom Line \!n"||dt_text;
Save Text File(filePath, out, mode("Replace"));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is there is cleaner way without saving file twice? (Let's say it's going to be for multiple files that are pretty big themselves - so extra save operation matters).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2023 19:36:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-save-CSV-file-with-custom-text-before-headers/m-p/665373#M85369</guid>
      <dc:creator>miguello</dc:creator>
      <dc:date>2023-08-03T19:36:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to save CSV file with custom text before headers</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-save-CSV-file-with-custom-text-before-headers/m-p/665401#M85370</link>
      <description>&lt;P&gt;You might want to look into reading the whole csv file into a text string using&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Load Text File()&lt;/P&gt;
&lt;P&gt;You can then parse the string variable for the information you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Save Text File()&lt;/P&gt;
&lt;P&gt;can then be used to write the file back to your hard drive.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2023 20:32:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-save-CSV-file-with-custom-text-before-headers/m-p/665401#M85370</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2023-08-03T20:32:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to save CSV file with custom text before headers</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-save-CSV-file-with-custom-text-before-headers/m-p/665423#M85372</link>
      <description>&lt;P&gt;Jim,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That's exactly what I'm doing in my current solution - see above.&lt;/P&gt;&lt;P&gt;The problem is that I need to do some data manipulation as well - so I need to load it as a data table as well.&lt;/P&gt;&lt;P&gt;The problem is how to get the data table into text (in CSV format)... I could only come up with save as CSV and then load it again as text in order in insert the string. This is one Save\Load cycle more than I'd hope to have - it becomes expensive when I have multiple large files.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2023 21:53:47 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-save-CSV-file-with-custom-text-before-headers/m-p/665423#M85372</guid>
      <dc:creator>miguello</dc:creator>
      <dc:date>2023-08-03T21:53:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to save CSV file with custom text before headers</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-save-CSV-file-with-custom-text-before-headers/m-p/665433#M85374</link>
      <description>&lt;P&gt;I believe your specified approach will prove to be the most efficient.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2023 22:03:19 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-save-CSV-file-with-custom-text-before-headers/m-p/665433#M85374</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2023-08-03T22:03:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to save CSV file with custom text before headers</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-save-CSV-file-with-custom-text-before-headers/m-p/666945#M85496</link>
      <description>&lt;P&gt;Thank you, I also want to know it.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2023 06:17:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-save-CSV-file-with-custom-text-before-headers/m-p/666945#M85496</guid>
      <dc:creator>TroyJones</dc:creator>
      <dc:date>2023-08-09T06:17:05Z</dc:date>
    </item>
  </channel>
</rss>

