title: converting an Excel (xls) file to a comma separated (csv) file without the GUI
body: <p>Is there a simple way to translate an XLS to a CSV formatted file without starting the Excel windowed application?</p>
  
  <p>I need to process some Excel XLS workbooks with scripts. For this i need to convert the xls file into a csv file. This can be done with a save-as from the Excel application. But, i would like to automate this (so, not open the Excel application window). </p>
  
  <p>It will suffice if the first sheet from the workbook gets translated to the CSV format.
  I need to just process data in that sheet.</p>
  
  <p>I have Cygwin and Excel installed on my system -- if that helps.</p>
  
  <p>Edit: Ok, i have a working solution with Perl. Updating for future use by others.</p>
  
  <p>I installed the <b>Spreadsheet::ParseExcel</b> module.
  and then used <a href="http://www.perlmonks.org/?node_id=170743" rel="nofollow noreferrer">read-excel.pl</a> sample.</p>
  
  <p>My code is a slight variation of this sample code, as below.</p>
  
  <pre><code>#!/usr/bin/perl -w
  # For each tab (worksheet) in a file (workbook),
  # spit out columns separated by ",",
  # and rows separated by c/r.
  
  use Spreadsheet::ParseExcel;
  use strict;
  
  my $filename = shift || "Book1.xls";
  my $e = new Spreadsheet::ParseExcel;
  my $eBook = $e-&gt;Parse($filename);
  my $sheets = $eBook-&gt;{SheetCount};
  my ($eSheet, $sheetName);
  
  foreach my $sheet (0 .. $sheets - 1) {
      $eSheet = $eBook-&gt;{Worksheet}[$sheet];
      $sheetName = $eSheet-&gt;{Name};
      print "#Worksheet $sheet: $sheetName\n";
      next unless (exists ($eSheet-&gt;{MaxRow}) and (exists ($eSheet-&gt;{MaxCol})));
      foreach my $row ($eSheet-&gt;{MinRow} .. $eSheet-&gt;{MaxRow}) {
          foreach my $column ($eSheet-&gt;{MinCol} .. $eSheet-&gt;{MaxCol}) {
              if (defined $eSheet-&gt;{Cells}[$row][$column])
              {
                  print $eSheet-&gt;{Cells}[$row][$column]-&gt;Value . ",";
              } else {
                  print ",";
              }
          }
          print "\n";
      }
  }
  </code></pre>
  
  <hr>
  
  <p><b>Update</b>: Here is a Powershell script that might also be easy to work with;
  as-is from <a href="http://blogs.msdn.com/krishkp/archive/2008/03/06/powershell-script-to-access-an-excel-file.aspx" rel="nofollow noreferrer">this MSDN blog</a> <a href="https://stackoverflow.com/questions/1021039/read-a-value-from-a-xls-file-using-bat-files">and, SO Reference</a>.</p>
  
  <pre><code>$excel = New-Object -comobject Excel.Application
  $workbooks = $excel.Workbooks.Open("C:\test.xlsx")
  $worksheets = $workbooks.Worksheets
  $worksheet = $worksheets.Item(1)
  $range = $worksheet.UsedRange
  foreach($row in $range.Rows)
  {
      foreach($col in $row.Columns)
      {
          echo $col.Text
      }
  }
  </code></pre>
  
  <hr>
  
  <p>Update: I recently came across a Windows tool <a href="http://csved.sjfrancke.nl/index.html" rel="nofollow noreferrer"><strong>CSVed</strong></a> at this <a href="https://superuser.com/questions/54356/program-to-display-csv-nicely-from-clipboard/54362#54362">Superuser answer</a> which might be useful to some people.</p>