lib/write_xlsx/workbook.rb in write_xlsx-0.81.1 vs lib/write_xlsx/workbook.rb in write_xlsx-0.83.0
- old
+ new
@@ -832,10 +832,21 @@
def add_vba_project(vba_project)
@vba_project = vba_project
end
#
+ # Set the VBA name for the workbook.
+ #
+ def set_vba_name(vba_codename = nil)
+ if vba_codename
+ @vba_codename = vba_codename
+ else
+ @vba_codename = 'ThisWorkbook'
+ end
+ end
+
+ #
# set_calc_mode()
#
# Set the Excel caclcuation mode for the workbook.
#
def set_calc_mode(mode, calc_id = nil)
@@ -969,10 +980,14 @@
def chartsheet_count
@worksheets.chartsheet_count
end
+ def non_chartsheet_count
+ @worksheets.worksheets.count
+ end
+
def style_properties
[
@xf_formats,
@palette,
@font_count,
@@ -990,10 +1005,18 @@
def num_comment_files
@worksheets.select { |sheet| sheet.has_comments? }.count
end
+ def chartsheets
+ @worksheets.chartsheets
+ end
+
+ def non_chartsheets
+ @worksheets.worksheets
+ end
+
private
def setup_filename(file) #:nodoc:
if file.respond_to?(:to_str) && file != ''
@filename = file
@@ -1535,10 +1558,11 @@
vml_drawing_id = 0
vml_data_id = 1
vml_header_id = 0
vml_shape_id = 1024
comment_files = 0
+ has_button = false
@worksheets.each do |sheet|
next if !sheet.has_vml? && !sheet.has_header_vml?
if sheet.has_vml?
if sheet.has_comments?
@@ -1558,13 +1582,28 @@
if sheet.has_header_vml?
vml_header_id += 1
vml_drawing_id += 1
sheet.prepare_header_vml_objects(vml_header_id, vml_drawing_id)
end
+
+ # Set the sheet vba_codename if it has a button and the workbook
+ # has a vbaProject binary.
+ unless sheet.buttons_data.empty?
+ has_button = true
+ if @vba_project && !sheet.vba_codename
+ sheet.set_vba_name
+ end
+ end
end
add_font_format_for_cell_comments if num_comment_files > 0
+
+ # Set the workbook vba_codename if one of the sheets has a button and
+ # the workbook has a vbaProject binary.
+ if has_button && @vba_project && !@vba_codename
+ set_vba_name
+ end
end
#
# Set the table ids for the worksheet tables.
#
@@ -1598,11 +1637,13 @@
seen_ranges = {}
# Map worksheet names to worksheet objects.
@worksheets.each { |worksheet| worksheets[worksheet.name] = worksheet }
- @charts.each do |chart|
+ # Build an array of the worksheet charts including any combined charts.
+ @charts.collect { |chart| [chart, chart.combined] }.flatten.compact.
+ each do |chart|
chart.formula_ids.each do |range, id|
# Skip if the series has user defined data.
if chart.formula_data[id]
seen_ranges[range] = chart.formula_data[id] unless seen_ranges[range]
next
@@ -1809,10 +1850,11 @@
end
end
# Sort the workbook charts references into the order that the were
# written from the worksheets above.
- @charts = @charts.sort_by { |chart| chart.id }
+ @charts = @charts.select { |chart| chart.id != -1 }.
+ sort_by { |chart| chart.id }
@drawing_count = drawing_id
end
#