Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I pulled down #set to GenericSpreedSheet #1

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions lib/roo/excel2003xml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,6 @@ def font(row, col, sheet=nil)
@style_definitions[style_name]
end

# set a cell to a certain value
# (this will not be saved back to the spreadsheet file!)
def set(row,col,value,sheet=nil) #:nodoc:
sheet ||= @default_sheet
read_cells(sheet) unless @cells_read[sheet]
row,col = normalize(row,col)
set_value(row,col,value,sheet)
if value.class == Fixnum
set_type(row,col,:float,sheet)
elsif value.class == String
set_type(row,col,:string,sheet)
elsif value.class == Float
set_type(row,col,:string,sheet)
else
raise ArgumentError, "Type for "+value.to_s+" not set"
end
end

# returns the type of a cell:
# * :float
# * :string
Expand Down Expand Up @@ -292,16 +274,6 @@ def read_styles
end
end

def set_value(row,col,value,sheet=nil)
sheet = @default_value unless sheet
@cell[sheet][[row,col]] = value
end

def set_type(row,col,type,sheet=nil)
sheet = @default_value unless sheet
@cell_type[sheet][[row,col]] = type
end

A_ROO_TYPE = {
"float" => :float,
"string" => :string,
Expand Down
30 changes: 0 additions & 30 deletions lib/roo/excelx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,24 +238,6 @@ def font(row, col, sheet=nil)
@style_definitions[s_attribute]
end

# set a cell to a certain value
# (this will not be saved back to the spreadsheet file!)
def set(row,col,value,sheet=nil) #:nodoc:
sheet ||= @default_sheet
read_cells(sheet) unless @cells_read[sheet]
row,col = normalize(row,col)
set_value(row,col,value,sheet)
if value.class == Fixnum
set_type(row,col,:float,sheet)
elsif value.class == String
set_type(row,col,:string,sheet)
elsif value.class == Float
set_type(row,col,:string,sheet)
else
raise ArgumentError, "Type for "+value.to_s+" not set"
end
end

# returns the type of a cell:
# * :float
# * :string,
Expand Down Expand Up @@ -633,18 +615,6 @@ def extract_content(tmpdir, zipfilename)
end
end

# sets the value of a cell
def set_value(row,col,value,sheet=nil)
sheet = @default_value unless sheet
@cell[sheet][[row,col]] = value
end

# sets the type of a cell
def set_type(row,col,type,sheet=nil)
sheet = @default_value unless sheet
@cell_type[sheet][[row,col]] = type
end

# read the shared strings xml document
def read_shared_strings(doc)
doc.xpath("//xmlns:si").each do |si|
Expand Down
24 changes: 24 additions & 0 deletions lib/roo/generic_spreadsheet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,22 @@ def column(columnnumber,sheet=nil)
end
end

# set a cell to a certain value
# (this will not be saved back to the spreadsheet file!)
def set(row,col,value,sheet=@default_sheet) #:nodoc:
read_cells(sheet) unless @cells_read[sheet]
row, col = normalize(row,col)
cell_type = case value
when Fixnum then :float
when String, Float then :string
else
raise ArgumentError, "Type for #{value} not set"
end

set_value(row,col,value,sheet)
set_type(row,col,cell_type,sheet)
end

# reopens and read a spreadsheet document
def reload
# von Abfrage der Klasse direkt auf .to_s == '..' umgestellt
Expand Down Expand Up @@ -562,6 +578,14 @@ def header_index(query)
row(@header_line).index(query) + first_column
end

def set_value(row,col,value,sheet=@default_value)
@cell[sheet][[row,col]] = value
end

def set_type(row,col,type,sheet=@default_value)
@cell_type[sheet][[row,col]] = type
end

# converts cell coordinate to numeric values of row,col
def normalize(row,col)
if row.class == String
Expand Down
12 changes: 12 additions & 0 deletions lib/roo/google.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ def empty?(row, col, sheet=nil)
value.empty?
end

# sets the cell to the content of 'value'
# a formula can be set in the form of '=SUM(...)'
def set(row,col,value,sheet=nil)
set_value(row,col,value,sheet=nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sheet=nil in the call to set_value will override the sheet argument.

end

# sets the cell to the content of 'value'
# a formula can be set in the form of '=SUM(...)'
def set_value(row,col,value,sheet=nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the other types, set_value is private and set is the main api. Maybe we could print a deprecation message here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides the deprecation warning, we could rename #set_value to #_set_value and make private, the GenericSpreadSheet protocol is already broken at this class, so I don't think it would be a problem.
Then can we remove the deprecation and rename #_set_value to #set_value in a future version.

Expand Down Expand Up @@ -223,6 +229,12 @@ def last_column(sheet=nil)

private

def set_type(row,col,type,sheet=nil)
sheet = @default_value unless sheet
key = "#{row},#{col}"
@cell_type[sheet][[key]] = type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this extra [] around key is a bug.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep

end

# read all cells in a sheet.
def read_cells(sheet=nil)
sheet ||= @default_sheet
Expand Down
28 changes: 0 additions & 28 deletions lib/roo/openoffice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,24 +162,6 @@ def font(row, col, sheet=nil)
@style_definitions[style_name]
end

# set a cell to a certain value
# (this will not be saved back to the spreadsheet file!)
def set(row,col,value,sheet=nil) #:nodoc:
sheet ||= @default_sheet
read_cells(sheet) unless @cells_read[sheet]
row,col = normalize(row,col)
set_value(row,col,value,sheet)
if value.class == Fixnum
set_type(row,col,:float,sheet)
elsif value.class == String
set_type(row,col,:string,sheet)
elsif value.class == Float
set_type(row,col,:string,sheet)
else
raise ArgumentError, "Type for "+value.to_s+" not set"
end
end

# returns the type of a cell:
# * :float
# * :string
Expand Down Expand Up @@ -490,16 +472,6 @@ def read_styles(style_elements)
end
end

def set_value(row,col,value,sheet=nil)
sheet = @default_value unless sheet
@cell[sheet][[row,col]] = value
end

def set_type(row,col,type,sheet=nil)
sheet = @default_value unless sheet
@cell_type[sheet][[row,col]] = type
end

A_ROO_TYPE = {
"float" => :float,
"string" => :string,
Expand Down