Sha256: 10d65fa01d9fb844f11d2a214af4f522485fc7d829b9d8b7a14474c8e012b930

Contents?: true

Size: 1.13 KB

Versions: 7

Compression:

Stored size: 1.13 KB

Contents

#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

##############################################################################
#
# An example of turning off worksheet cells errors/warnings using the
# Excel::Writer::XLSX module.
#
# Copyright 2000-2021, John McNamara, jmcnamara@cpan.org
# convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
#

require 'write_xlsx'

workbook = WriteXLSX.new('ignore_errors.xlsx')
worksheet = workbook.add_worksheet

# Write strings that looks like numbers. This will cause an Excel warning.
worksheet.write_string('C2', '123')
worksheet.write_string('C3', '123')

# Write a divide by zero formula. This will also cause an Excel warning.
worksheet.write_formula('C5', '=1/0')
worksheet.write_formula('C6', '=1/0')

# Turn off some of the warnings:
worksheet.ignore_errors(
  number_stored_as_text: 'C3',
  eval_error:            'C6'
)

# Write some descriptions for the cells and make the column wider for clarity.
worksheet.set_column('B:B', 16)
worksheet.write('B2', 'Warning:')
worksheet.write('B3', 'Warning turned off:')
worksheet.write('B5', 'Warning:')
worksheet.write('B6', 'Warning turned off:')

workbook.close

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
write_xlsx-1.12.1 examples/ignore_errors.rb
write_xlsx-1.12.0 examples/ignore_errors.rb
write_xlsx-1.11.2 examples/ignore_errors.rb
write_xlsx-1.11.1 examples/ignore_errors.rb
write_xlsx-1.11.0 examples/ignore_errors.rb
write_xlsx-1.10.2 examples/ignore_errors.rb
write_xlsx-1.10.1 examples/ignore_errors.rb