Class: Ruport::Formatter::XLSXML
- Inherits:
-
Ruport::Formatter
- Object
- Ruport::Formatter
- Ruport::Formatter::XLSXML
- Defined in:
- lib/ruport/util/xls.rb
Overview
Excel 2003 XML
Instance Method Summary collapse
- #build_cells(values, style = '') ⇒ Object
- #build_row ⇒ Object
- #build_table_body ⇒ Object
- #build_table_header ⇒ Object
- #finalize_table ⇒ Object
- #prepare_table ⇒ Object
- #table_row ⇒ Object
Instance Method Details
#build_cells(values, style = '') ⇒ Object
271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/ruport/util/xls.rb', line 271 def build_cells(values, style = '') values.each do |value| value = CGI.escapeHTML(value.to_s) if style.length > 0 output << %{ <Cell>\n} else output << %{ <Cell ss:StyleID="#{style}">\n} end output << %{ <Data ss:Type="String">#{value}</Data>\n} output << %{ </Cell>\n} end end |
#build_row ⇒ Object
261 262 263 |
# File 'lib/ruport/util/xls.rb', line 261 def build_row table_row{ build_cells(data.to_a) } end |
#build_table_body ⇒ Object
255 256 257 258 259 |
# File 'lib/ruport/util/xls.rb', line 255 def build_table_body data.each do |r| table_row { build_cells(r) } end end |
#build_table_header ⇒ Object
249 250 251 252 253 |
# File 'lib/ruport/util/xls.rb', line 249 def build_table_header if .show_table_headers table_row { build_cells(data.column_names, 'Heading') } end end |
#finalize_table ⇒ Object
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/ruport/util/xls.rb', line 284 def finalize_table output << %{ </Table> </ss:Worksheet> </Workbook>} @tempfile = Tempfile.new('output.xls') @tempfile.print(output) @tempfile.close(); .io = if .tempfile @tempfile else File.read(@tempfile.path) end end |
#prepare_table ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/ruport/util/xls.rb', line 224 def prepare_table output << %{<?xml version="1.0" encoding="UTF-8"?><?mso-application progid="Excel.Sheet"?> <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"> <Styles> <Style ss:ID="Default" ss:Name="Default"/> <Style ss:ID="Heading" ss:Name="Heading">#{options.header_style || ' <Alignment ss:Horizontal="Center"/> <Font ss:Bold="1" ss:Italic="1" ss:Size="12"/>'} </Style> <Style ss:ID="co1"/> <Style ss:ID="ta1"/> </Styles> <ss:Worksheet ss:Name="#{options.worksheet_name || 'Ruport'}"> <Table ss:StyleID="ta1"> } data.column_names.size.times { output << %{<Column ss:AutoFitWidth="1"/>} } end |
#table_row ⇒ Object
265 266 267 268 269 |
# File 'lib/ruport/util/xls.rb', line 265 def table_row output << %{ <Row>\n} yield output << %{ </Row>\n} end |