lib/rspreadsheet/tools.rb in rspreadsheet-0.2.0 vs lib/rspreadsheet/tools.rb in rspreadsheet-0.2.3

- old
+ new

@@ -12,13 +12,22 @@ colname = addr[0] rowname = addr[1] else raise 'Wrong number of arguments' end - - colname=colname.rjust(3,'@') - col = (colname[-1].ord-64)+(colname[-2].ord-64)*26+(colname[-3].ord-64)*26*26 + + ## first possibility how to implement it +# colname=colname.rjust(3,'@') +# col = (colname[-1].ord-64)+(colname[-2].ord-64)*26+(colname[-3].ord-64)*26*26 + + ## second possibility how to implement it + # col=(colname.to_i(36)-('A'*colname.size).to_i(36)).to_s(36).to_i(26)+('1'*colname.size).to_i(26) + + ## third possibility how to implement it (second one little shortened) + s=colname.size + col=(colname.to_i(36)-(36**s-1).div(3.5)).to_s(36).to_i(26)+(26**s-1)/25 + row = rowname.to_i return [row,col] end def self.convert_cell_coordinates_to_address(*coords) coords = coords[0] if coords.length == 1 @@ -113,11 +122,11 @@ end def self.remove_ns_attribute(node,ns_prefix,key) node.attributes.get_attribute_ns(Tools.get_namespace(ns_prefix).href,key) attr.remove! unless attr.nil? end - def self.create_ns_node(nodename,ns_prefix) - LibXML::XML::Node.new(nodename,nil, Tools.get_namespace(ns_prefix)) + def self.create_ns_node(ns_prefix,nodename,value=nil) + LibXML::XML::Node.new(nodename,value, Tools.get_namespace(ns_prefix)) end end end \ No newline at end of file