2

I am using DataNitro in my spreadsheet. When I write the values to a cell. It automatically guesses if format looks like a date. This is obviously not always helpfull!

dt_str = "08/20/13"
Cell("A1").value = dt_str
# puts date type in that cell

I am not sure whether this behaviour is from Excel 2010 or from DataNitro side. As I am writing this i am getting more convinced that this is an Excel issue. Anybody with experience on this?

Done some more research and I almost conviced it is Excel Issue. Solutions when Entering data directly is starting the cell with a ' This is obviously? not possible if I come in from python.

Joop
  • 7,840
  • 9
  • 43
  • 58

1 Answers1

3

This is an Excel issue, and putting a single quote at the beginning is correct. You can do that as long as you use double quotes to delimit the string:

Cell("A1").value = "'10/1/2013"
Ben Lerner
  • 1,318
  • 9
  • 12
  • thanks. I am using the .table method to write a list of lists to excel. Any way of influencing the behavior there. Mixture of text, floats and dates that I would prefer to keep in text. Btw is there a way to set custom format (for date) from DataNitro? – Joop Oct 01 '13 at 19:10
  • 1
    You can use a nested list comprehension: new_table = [["'" + str(a) for a in b] for b in old_table] There's no way to set custom formats for now, but you can use strftime to write dates as custom texts. – Ben Lerner Oct 02 '13 at 00:31