zdavatz / spreadsheet

The Ruby Spreadsheet by ywesee GmbH
http://spreadsheet.ch
GNU General Public License v3.0
1.13k stars 240 forks source link

Hyperlink not working when adding to an existing worksheet #130

Closed micred closed 9 years ago

micred commented 9 years ago

Hi, I'm able to correctly add link to xls file when creating new worksheets (book.create_worksheet), but links added to an existing worksheet doesn't work.

Example:

require 'spreadsheet'

book = Spreadsheet.open('Workbook2.xls', 'rb')
sheet = book.worksheet(0)
sheet[0,0] = Spreadsheet::Link.new('www.google.com', 'link text')
book.write 'spreadsheet_with_link.xls'

Workbook2.xls is an empty spreadsheet created by Excel for Mac 2011. I also try creating the file with LibreOffice and I got the same result.

Maybe I need to force cell reset before adding the hyperlink?!

zdavatz commented 9 years ago

Can you please link your sample file here.

micred commented 9 years ago

Here: https://dl.dropboxusercontent.com/u/11188592/Workbook1.xls https://dl.dropboxusercontent.com/u/11188592/Workbook2.xls

With Workbook2.xls I also get "File error: data may have been lost" when opened.

Tested on Ruby 2.1.5, 2.1.2-p95 and 1.9.3-p547. Gem version 1.0.2 and latest from github (master branch).

zdavatz commented 9 years ago

Have you tried the solution you proposed?

micred commented 9 years ago

How exactly do you suggest?

zdavatz commented 9 years ago

play with the row formatting, also see here: https://github.com/zdavatz/spreadsheet/blob/master/GUIDE.md

micred commented 9 years ago

I had no luck. BTW the format look the same of a cell with a working link created by Excel and a cell with a link created by spreadsheet gem:

=> #<Spreadsheet::Format:0x007ffed28dd528 @font=#<Spreadsheet::Font:0x007ffed294c2e8 @name="Arial", @color=:text, @previous_fast_key=nil, @size=10, @weight=400, @italic=false, @strikeout=false, @outline=false, @shadow=false, @escapement=:normal, @underline=:none, @family=:swiss, @encoding=:iso_latin1>, @number_format="GENERAL", @rotation=0, @pattern=0, @bottom_color=:builtin_black, @top_color=:builtin_black, @left_color=:builtin_black, @right_color=:builtin_black, @diagonal_color=:builtin_black, @pattern_fg_color=:border, @pattern_bg_color=:pattern_bg, @regexes={:date=>/[YMD]/, :date_or_time=>/[hmsYMD]/, :datetime=>/([YMD].*[HS])|([HS].*[YMD])/, :time=>/[hms]/, :number=>/[#]/}, @used_merge=0, @horizontal_align=:default, @text_wrap=false, @vertical_align=:bottom, @rotation_stacked=false, @indent_level=0, @shrink=false, @text_direction=:context, @left=:none, @right=:none, @top=:none, @bottom=:none, @cross_down=false, @cross_up=false> 
zdavatz commented 9 years ago

what formatting did you try? Please show the code.

zdavatz commented 9 years ago

Please also ask your question here: https://groups.google.com/forum/#!forum/rubyspreadsheet and also search that group.

micred commented 9 years ago

Random trial and error to be honest :-) Ok, for reference: https://groups.google.com/forum/#!topic/rubyspreadsheet/Nn1nTaiQyI8 Thank you.

zdavatz commented 9 years ago

Try setting the format to "link" as in

row.format(3).number_format
micred commented 9 years ago

How to set link?! I found only number, time, date format in documentation...

micred commented 9 years ago

Still no hints? Thank you.

zdavatz commented 9 years ago

Not at the moment.

cyberkostyan commented 8 years ago

Hi, no any update?

zdavatz commented 8 years ago

Sorry, not yet.