<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>lib/controllers/reports_controller.rb.template</filename>
    </added>
    <added>
      <filename>spec/reports_controller_spec.rb</filename>
    </added>
    <added>
      <filename>test.sqlite3</filename>
    </added>
    <added>
      <filename>test.xls</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1 +1,2 @@
+Mime::Type.register &quot;application/vnd.ms-excel&quot;, :xls
 </diff>
      <filename>init.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,8 +1,7 @@
 require 'fileutils'
 
 dir = File.dirname(__FILE__)
-FileUtils.cp Dir[File.join(dir, 'lib', 'controllers', '*.rb')], File.join(dir, '../../../app/controllers')
+FileUtils.cp File.join(dir, 'lib', 'controllers', 'reports_controller.rb.template'), File.join(dir, '../../../app/controllers/reports_controller.rb')
 FileUtils.cp_r Dir[File.join(dir, 'views', '*')], File.join(dir, '../../../app/views')
 
-
 puts IO.read(File.join(File.dirname(__FILE__), 'INSTALL'))
\ No newline at end of file</diff>
      <filename>install.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,8 @@
+require &quot;spreadsheet/excel&quot;
+require 'iconv'
+
 class ReportsController &lt; ApplicationController
+  include Spreadsheet
 
   def index
     @reports = Report.find :all
@@ -6,27 +10,52 @@ class ReportsController &lt; ApplicationController
   
   def show
     @report = Report.find(params[:id])
-    @results = @report.run
+    data = @report.run
     respond_to do |format|
       format.html do
-        if @results.is_a? Array
-          @results = @results.inject('&lt;table&gt;') do |table, row|
-            table &lt;&lt; '&lt;tr&gt;'
-            table &lt;&lt; row.inject('') {|_row, cell| _row &lt;&lt; &quot;&lt;td&gt;#{cell.to_s}&lt;/td&gt;&quot;}
-            table &lt;&lt; '&lt;/tr&gt;'
-          end &lt;&lt; '&lt;/table&gt;'
-        end
+        @table = create_html_table data
       end
       format.csv do
-        if @results.is_a? Array
-          @results = @results.inject('') do |table, row|
-            table &lt;&lt; row.map {|cell| cell.to_s.gsub(/\s+/, ' ')}.join(';')
-            table &lt;&lt; &quot;\n&quot;
-          end
-        end
-        render :text =&gt; @results
+        render :text =&gt; create_csv_table(data)
+        headers['Content-Disposition'] = &quot;attachment; filename=\&quot;#{@report.name.downcase.gsub(/\s+/, '_')}_#{Date.today.to_s}.csv\&quot;&quot;
+      end
+      format.xls do
+        render :text =&gt; create_excel_table(data)
+        headers['Content-Disposition'] = &quot;attachment; filename=\&quot;#{@report.name.downcase.gsub(/\s+/, '_')}_#{Date.today.to_s}.xls\&quot;&quot;
+        headers['Cache-Control'] = ''
+      end
+    end
+  end
+  
+  def create_html_table(_table)
+    _table.inject('&lt;table&gt;') do |table, row|
+      table &lt;&lt; '&lt;tr&gt;'
+      table &lt;&lt; row.inject('') {|_row, cell| _row &lt;&lt; &quot;&lt;td&gt;#{cell.to_s}&lt;/td&gt;&quot;}
+      table &lt;&lt; '&lt;/tr&gt;'
+    end &lt;&lt; '&lt;/table&gt;'
+  end
+  
+  def create_csv_table(_table)
+    _table.inject('') do |table, row|
+      table &lt;&lt; row.map {|cell| cell.to_s.gsub(/\s+/, ' ')}.join(';')
+      table &lt;&lt; &quot;\n&quot;
+    end
+  end
+  
+  def create_excel_table(_table)
+    out = StringIO.new
+    workbook = Excel.new(out)
+    format = Format.new
+    
+    worksheet = workbook.add_worksheet
+    _table.each_with_index do |row, i| 
+      row.each_with_index do |col, j|
+        worksheet.write i, j, Iconv.conv('ISO-8859-1', 'UTF-8', col.to_s), format # excel doesn't seem to like utf-8
       end
     end
+    
+    workbook.close
+    out.string
   end
   
 end</diff>
      <filename>lib/controllers/reports_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -10,4 +10,49 @@ ActiveRecord::Base.establish_connection :adapter =&gt; 'sqlite3', :database =&gt; File
 # migrate
 
 require File.dirname(__FILE__) + '/../generators/dead_simple_reports/templates/migration'
-CreateDeadSimpleReports.up
\ No newline at end of file
+CreateDeadSimpleReports.up
+
+# rails controller stuff
+
+class ApplicationController
+  class MimeTypeFormat
+    
+    [:html, :csv, :xls].each do |mime_type|
+    
+      eval &lt;&lt;-CODE
+      def #{mime_type}(&amp;block)
+        @#{mime_type}_block = block
+      end
+      
+      def #{mime_type}_view
+        @#{mime_type}_block.call
+      end
+      
+      CODE
+      
+    end
+    
+  end
+  
+  def respond_to(&amp;formatter)
+    @format = MimeTypeFormat.new
+    formatter.call @format
+    @format
+  end
+  
+  def params
+    {}
+  end
+  
+  def headers
+    {}
+  end
+  
+  def render(options = {})
+    @view = options[:text]
+  end
+  
+  def view
+    @view
+  end
+end
\ No newline at end of file</diff>
      <filename>spec/spec_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,6 +2,12 @@
 
 &lt;ol&gt;
   &lt;%- @reports.each do |report| -%&gt;
-    &lt;li&gt;&lt;%= link_to h(report.name), :action =&gt; 'show', :id =&gt; report.id %&gt; (&lt;%= link_to 'CSV', :action =&gt; 'show', :id =&gt; report.id, :format =&gt; 'csv' %&gt;)&lt;/li&gt;
+    &lt;li&gt;
+			&lt;%= link_to h(report.name), :action =&gt; 'show', :id =&gt; report.id %&gt;
+			(
+				&lt;%= link_to 'CSV', :action =&gt; 'show', :id =&gt; report.id, :format =&gt; 'csv' %&gt;
+				&lt;%= link_to 'Excel', :action =&gt; 'show', :id =&gt; report.id, :format =&gt; 'xls' %&gt;
+			)
+		&lt;/li&gt;
   &lt;%- end -%&gt;
 &lt;/ol&gt;
\ No newline at end of file</diff>
      <filename>views/reports/index.rhtml</filename>
    </modified>
    <modified>
      <diff>@@ -1,17 +1,6 @@
 &lt;h1&gt;&lt;%= h @report.name %&gt;&lt;/h1&gt;
 
-&lt;p&gt;Format: &lt;%= link_to 'CSV', :format =&gt; 'csv' %&gt;&lt;/p&gt;
+&lt;p&gt;Format: &lt;%= link_to 'CSV', :format =&gt; 'csv' %&gt;, &lt;%= link_to 'Excel', :format =&gt; 'xls' %&gt;&lt;/p&gt;
 
-&lt;style&gt;
-  table {
-    border-collapse: collapse;
-  }
-
-  td {
-    border: 1px solid black;
-    padding: 3px;
-  }
-&lt;/style&gt;
-
-&lt;%= @results %&gt;
+&lt;%= @table %&gt;
 </diff>
      <filename>views/reports/show.rhtml</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>1ce6c51ed41b92df86e66bf14ce8aa3db5831161</id>
    </parent>
  </parents>
  <author>
    <name>Alexander Lang</name>
    <email>alex@skywalker.(none)</email>
  </author>
  <url>http://github.com/langalex/dead_simple_reports/commit/61fea284d033406dab26044912dec36e652a0327</url>
  <id>61fea284d033406dab26044912dec36e652a0327</id>
  <committed-date>2008-04-12T12:51:43-07:00</committed-date>
  <authored-date>2008-04-12T12:51:43-07:00</authored-date>
  <message>added excel format reports via the spreadsheet-excel gem, added specs, changed install to copy fewer files into the app so that updates are easier</message>
  <tree>90393b0b4a65eab7886ba2db6a7569a3ad619e64</tree>
  <committer>
    <name>Alexander Lang</name>
    <email>alex@skywalker.(none)</email>
  </committer>
</commit>
