lib/write_xlsx/workbook.rb in write_xlsx-0.97.0 vs lib/write_xlsx/workbook.rb in write_xlsx-0.99.0

- old
+ new

@@ -121,11 +121,11 @@ @optimization = options[:optimization] || 0 @x_window = 240 @y_window = 15 @window_width = 16095 @window_height = 9660 - @tab_ratio = 500 + @tab_ratio = 600 @excel2003_style = options[:excel2003_style] || false @table_count = 0 @image_types = {} @images = [] @strings_to_urls = (options[:strings_to_urls].nil? || options[:strings_to_urls]) ? true : false @@ -783,10 +783,23 @@ @window_height = 9660 end end # + # Set the ratio of space for worksheet tabs. + # + def set_tab_ratio(tab_ratio = nil) + return if !tab_ratio + + if tab_ratio < 0 || tab_ratio > 100 + raise "Tab ratio outside range: 0 <= zoom <= 100" + else + @tab_ratio = (tab_ratio * 10).to_i + end + end + + # # The set_properties method can be used to set the document properties # of the Excel file created by WriteXLSX. These properties are visible # when you use the Office Button -> Prepare -> Properties option in Excel # and are also available to external applications that read or index windows # files. @@ -1306,11 +1319,11 @@ ['xWindow', @x_window], ['yWindow', @y_window], ['windowWidth', @window_width], ['windowHeight', @window_height] ] - if @tab_ratio != 500 + if @tab_ratio != 600 attributes << ['tabRatio', @tab_ratio] end if @firstsheet > 0 attributes << ['firstSheet', @firstsheet + 1] end @@ -1510,13 +1523,21 @@ # Check if num_format is an index to a built-in number format. # Also check for a string of zeros, which is a valid number format # string but would evaluate to zero. # if num_format.to_s =~ /^\d+$/ && num_format.to_s !~ /^0+\d/ + # Number format '0' is indexed as 1 in Excel. + if num_format == 0 + num_format = 1 + end # Index to a built-in number format. format.num_format_index = num_format next + elsif num_format.to_s == 'General' + # The 'General' format has an number format index of 0. + format.num_format_index = 0 + next end if num_formats[num_format] # Number format has already been used. format.num_format_index = num_formats[num_format] @@ -2062,19 +2083,23 @@ y_dpi = 96 offset = 2 data_length = data.bytesize - # Search through the image data to read the height and width in the - # 0xFFC0/C2 element. Also read the DPI in the 0xFFE0 element. + # Search through the image data to read the JPEG markers. while offset < data_length marker = data[offset+0, 2].unpack("n")[0] length = data[offset+2, 2].unpack("n")[0] - if marker == 0xFFC0 || marker == 0xFFC2 + # Read the height and width in the 0xFFCn elements + # (Except C4, C8 and CC which aren't SOF markers). + if (marker & 0xFFF0) == 0xFFC0 && + marker != 0xFFC4 && marker != 0xFFCC height = data[offset+5, 2].unpack("n")[0] width = data[offset+7, 2].unpack("n")[0] end + + # Read the DPI in the 0xFFE0 element. if marker == 0xFFE0 units = data[offset + 11, 1].unpack("C")[0] x_density = data[offset + 12, 2].unpack("n")[0] y_density = data[offset + 14, 2].unpack("n")[0]