summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/workbook/worksheet/table.rb
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-04-01 00:35:26 +0900
committerRandy Morgan <[email protected]>2012-04-01 00:35:26 +0900
commit22a341841f191a5aa00e87b1f166b4f25cc67f0a (patch)
tree505f46708d5cac7d33d0dd6679c125e2eb819075 /lib/axlsx/workbook/worksheet/table.rb
parentbb2117ba17297e02a0fc6d5ad5a22462e72a9a79 (diff)
downloadcaxlsx-22a341841f191a5aa00e87b1f166b4f25cc67f0a.tar.gz
caxlsx-22a341841f191a5aa00e87b1f166b4f25cc67f0a.zip
part way through changing all serialization to use string concatenation prior to dropping Nokogiri dep in production.
Diffstat (limited to 'lib/axlsx/workbook/worksheet/table.rb')
-rw-r--r--lib/axlsx/workbook/worksheet/table.rb32
1 files changed, 14 insertions, 18 deletions
diff --git a/lib/axlsx/workbook/worksheet/table.rb b/lib/axlsx/workbook/worksheet/table.rb
index 831040f3..0b1dc385 100644
--- a/lib/axlsx/workbook/worksheet/table.rb
+++ b/lib/axlsx/workbook/worksheet/table.rb
@@ -63,29 +63,25 @@ module Axlsx
end
end
+ def to_xml_string(str = '')
+ str << '<?xml version="1.0" encoding="UTF-8"?>'
+ str << '<table xmlns="' << XML_NS << '" id="' << (index+1).to_s << '" name="' << @name << '" displayName="' << @name.gsub(/\s/,'_') << '" '
+ str << 'ref="' << @ref << '" totalsRowShown="0">'
+ str << '<autoFilter ref="' << @ref << '"/>'
+ str << '<tableColumns count="' << header_cells.length.to_s << '">'
+ header_cells.each_with_index do |cell,index|
+ str << '<tableColumn id ="' << (index+1).to_s << '" name="' << cell.value << '"/>'
+ end
+ str << '</tableColumns>'
+ #TODO implement tableStyleInfo
+ str << '<tableStyleInfo showFirstColumn="0" showLastColumn="0" showRowStripes="1" showColumnStripes="0" name="TableStyleMedium9" />'
+ str << '</table>'
+ end
# The style for the table.
# TODO
# def style=(v) DataTypeValidator.validate "Table.style", Integer, v, lambda { |arg| arg >= 1 && arg <= 48 }; @style = v; end
- # Table Serialization
- # serializes the table
- def to_xml
- builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
- xml.table(:xmlns => XML_NS, :id => index+1, :name => @name, :displayName => @name.gsub(/\s/,'_'), :ref => @ref, :totalsRowShown => 0) {
- xml.autoFilter :ref=>@ref
- xml.tableColumns(:count => header_cells.length) {
- header_cells.each_with_index do |cell,index|
- xml.tableColumn :id => index+1, :name => cell.value
- end
- }
- xml.tableStyleInfo :showFirstColumn=>"0", :showLastColumn=>"0", :showRowStripes=>"1", :showColumnStripes=>"0", :name=>"TableStyleMedium9"
- #TODO implement tableStyleInfo
- }
- end
- builder.to_xml(:save_with => 0)
- end
-
private
# get the header cells (hackish)