Hello I have an html table which presents working hours for projects In the past 2 days I was trying to export this table to excel file. Finally i was able to do this by using an xml builder template. Here is my file
xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
xml.Workbook({
'xmlns' => "urn:schemas-microsoft-com:office:spreadsheet",
'xmlns:o' => "urn:schemas-microsoft-com:office:office",
'xmlns:x' => "urn:schemas-microsoft-com:office:excel",
'xmlns:html' => "http://www.w3.org/TR/REC-html40",
'xmlns:ss' => "urn:schemas-microsoft-com:office:spreadsheet"
}) do
xml.Styles do
xml.Style 'ss:ID' => 'Default', 'ss:Name' =>'Normal' do
xml.Alignment 'ss:Vertical' => 'Bottom','ss:Horizontal' => 'Center'
xml.Borders
xml.Font 'ss:FontName' => 'Verdana'
xml.Interior
xml.NumberFormat
end
xml.Style 'ss:ID' => 'header' do
xml.Alignment 'ss:Vertical' => 'Bottom',
'ss:Horizontal' => 'Center'
xml.Font 'ss:FontName' => 'Arial','ss:Bold'=>'1'
xml.Interior 'ss:Color'=>'#99CCFF', 'ss:Pattern'=>'Solid'
end
end
xml.Worksheet 'ss:Name' => 'Projects Reports' do
xml.Table 'ss:DefaultColumnWidth'=>'100','ss:DefaultRowHeight' => '15' do
# Header
xml.Row 'ss:StyleID' => 'header' do
xml.Cell { xml.Data 'ID', 'ss:Type' => 'String' }
xml.Cell { xml.Data 'NAME', 'ss:Type' => 'String' }
xml.Cell { xml.Data 'Actual Hours', 'ss:Type' => 'String' }
xml.Cell { xml.Data 'Estimated Hours', 'ss:Type' => 'String' }
xml.Cell { xml.Data 'Deadline', 'ss:Type' => 'String' }
end
# Rows
for project in @projects
xml.Row do
xml.Cell { xml.Data project.id, 'ss:Type' => 'Number' }
xml.Cell { xml.Data project.name, 'ss:Type' => 'String' }
xml.Cell { xml.Data project.working_hours, 'ss:Type' => 'String' }
xml.Cell { xml.Data project.estimated_hours, 'ss:Type' => 'String' }
xml.Cell { xml.Data project.deadline, 'ss:Type' => 'String' }
end
end
end
end
end
In my original html view I display in the bottom of the table the sum of project working hours and I want that this property will be also displayed in the Excel file. I did some checking in Google but didn’t find anything that can help me. I will appreciate if anyone can give me some direction to how I can write it in the xml builder file