lib/fast_excel.rb in fast_excel-0.4.0 vs lib/fast_excel.rb in fast_excel-0.4.1
- old
+ new
@@ -89,12 +89,15 @@
# Offset argument should be number of seconds, if not specified then it will use Time.zone.utc_offset || 0
#
# https://support.microsoft.com/en-us/help/214330/differences-between-the-1900-and-the-1904-date-system-in-excel
def self.date_num(time, offset = nil)
unless offset
- # Try use Rails' app timezone
- if Time.respond_to?(:zone)
+ # Try use value utc_offset
+ if time.respond_to?(:utc_offset)
+ offset = time.utc_offset
+ # Else try use Rails' app timezone
+ elsif Time.respond_to?(:zone) && !Time.zone.nil?
offset = Time.zone.utc_offset
else
offset = 0 # rollback to UTC
end
end
@@ -120,10 +123,11 @@
end
nil
end
+ ERROR_ENUM = Libxlsxwriter.enum_type(:error)
COLOR_ENUM = Libxlsxwriter.enum_type(:defined_colors)
EXTRA_COLORS = {
alice_blue: 0xF0F8FF,
antique_white: 0xFAEBD7,
aqua: 0x00FFFF,
@@ -361,13 +365,14 @@
format
end
def add_worksheet(sheetname = nil)
if !sheetname.nil?
- if sheetname.length > Libxlsxwriter::SHEETNAME_MAX
- raise ArgumentError, "Worksheet name '#{sheetname}' exceeds Excel's limit of #{Libxlsxwriter::SHEETNAME_MAX} characters"
- elsif @sheet_names.include?(sheetname)
- raise ArgumentError, "Worksheet name '#{sheetname}' is already in use"
+ error = validate_worksheet_name(sheetname)
+ if error != :no_error
+ error_code = ERROR_ENUM.find(error)
+ error_str = error_code ? Libxlsxwriter.strerror(error_code) : ''
+ raise ArgumentError, "Invalid worksheet name '#{sheetname}': (#{error_code} - #{error}) #{error_str}"
end
end
sheet = super(sheetname)
sheet.workbook = self