title: Load String of comma-separated-values (csv) into Quickoffice or Google Doc
body: <p>I am writing an Android App that collects data as a String of comma-separated-values (terminating each line with '\n') and then emails me the data once a month.</p>
  
  <p>One of my beta-testers has informed me that he would like to be able to view the intermediate data between uploads.  The natural way to do this (to my mind) would be to load the data to an "excel-like" app (such as QuickOffice or google doc's viewer).  I tried writing the String out to a file and then loading it into QuickOffice.  I can get QuickOffice to launch, but the file comes up blank.  Also, when I look for the file on my SD card, I can't find it.</p>
  
  <p>My code:</p>
  
  <pre><code>File root = Environment.getExternalStorageDirectory();
  try
  {
      BufferedWriter out = new BufferedWriter(new FileWriter(root.toString() + "/ww.csv"));
      out.write(getPreferences(MODE_PRIVATE).getString("allTrips", ""));
      out.flush();  // Probably not necessary
      out.close();
  }
  catch (IOException e)
  {
      // TODO Auto-generated catch block
      e.printStackTrace();
  }
  
  Intent i1 = new Intent(android.content.Intent.ACTION_VIEW);
  Uri data = Uri.fromFile(new File(root.toString() + "/ww.csv"));
  i1.setDataAndType(data, "application/vnd.ms-excel");
  startActivity(i1);
  </code></pre>
  
  <p>Please let me know what I'm doing wrong.  I'm open to small tweaks to my code above, as well as completely different approaches that get the job done.</p>
  
  <p>Before you ask, I remembered to add </p>
  
  <pre><code>    &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;
  </code></pre>
  
  <p>to my manifest.</p>
  
  <p>Also, I'm as happy to write to the Internal File System instead of the SD card (my data are small) but I couldn't get that to even open QuickOffice.</p>
  
  <p>An example of the data:</p>
  
  <pre><code>09/19/2011,AP2,Home,GW Parkway,12:03 PM,12:41 PM,38,Dry,Day
  09/20/2011,Home,AP2,MacArthur Blvd,7:18 AM,8:32 AM,74,Rain,Day
  09/20/2011,AP2,Home,Rock Creek Pkwy (Blagden),4:51 PM,5:45 PM,54,Dry,Day
  09/21/2011,Home,AP2,Rte 295,6:44 AM,7:36 AM,52,Rain,Day
  </code></pre>
  
  <p>Thanks.</p>
  
  <p>UPDATE (OCT 09 2011):</p>
  
  <p>Sometimes when writing code, you need to take a step back and rethink what you're trying to accomplish.  All I want to do is reformat my interim data and make an easy-to-read table to the user can see the data in-between monthly uploads.  I <em>thought</em> the easiest way to do this would be to load my .csv file into a spreadsheet.  Nikolay's suggestion of using an outside library to ensure that my file was properly formatted might have worked, but I'm trying to keep this app as lean as possible, so I want to avoid using (and learning to use) external libraries unnecessarily.  So, my end solution has been to write a slightly larger file to the SD card using html format and then opening the file as text/html rather than text/plain or application/vnd.ms-excel.  That took about an hour of coding and has solved the issue nicely, so I'm going to consider the problem closed.</p>