Method: Worksheet#write_date_time

Defined in:
lib/WriteExcel/worksheet.rb

#write_date_time(*args) ⇒ Object

write_date_time ($row, $col, $string, $format)

Write a datetime string in ISO8601 “yyyy-mm-ddThh:mm:ss.ss” format as a number representing an Excel date. $format is optional.

Returns 0 : normal termination

-1 : insufficient number of arguments
-2 : row or column out of range
-3 : Invalid date_time, written as string


2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
# File 'lib/WriteExcel/worksheet.rb', line 2544

def write_date_time(*args)
  # Check for a cell reference in A1 notation and substitute row and column
  if args[0] =~ /^\D/
    args = substitute_cellref(*args)
  end

  return -1 if (args.size < 3)                 # Check the number of args

  row       = args[0]                           # Zero indexed row
  col       = args[1]                           # Zero indexed column
  str       = args[2]

  # Check that row and col are valid and store max and min values
  return -2 if check_dimensions(row, col) != 0

  error     = 0
  date_time = convert_date_time(str)

  unless date_time.nil?
    error = write_number(row, col, date_time, args[3])
  else
    # The date isn't valid so write it as a string.
    write_string(row, col, str, args[3])
    error = -3
  end
  return error
end