7

I am currently creating XLS files programatically using Python and the XLWT/XLRD libraries.

I've been able to fill the cells with values and insert simple formulas. My challenge is that I want to create a drop down for my users (http://office.microsoft.com/en-us/excel-help/create-or-remove-a-drop-down-list-HP005202215.aspx)

Yes, I can easily do this in EXCEL, but I need to have this process automated - I'm using Python and the XLWT/XLRD libraries - I'd rather stick with them, but I'll switch to something else if necessary (I'm in a Ubuntu Linux Server).

Rostyslav Dzinko
  • 39,424
  • 5
  • 49
  • 62
pirhac
  • 887
  • 2
  • 8
  • 16

5 Answers5

8

openpyxl also supports drop down cell in XLSX files via data validation: http://openpyxl.readthedocs.org/en/latest/validation.html

Karthic Raghupathi
  • 2,011
  • 5
  • 41
  • 57
4

Just for the record, xlsxwriter can handle drop down lists on XLSX:

https://xlsxwriter.readthedocs.org/en/latest/example_data_validate.html

GermanK
  • 1,676
  • 2
  • 14
  • 21
3

Short answer: you can not - unsupported by XLWT/XLRD.

0
worksheet = workbook['SheetName']
dv = DataValidation(type="list", formula1=formula, allow_blank=False, showDropDown=False)
worksheet.add_data_validation(dv)
dv.add(worksheet["D7"]) # cell in worksheet where drop-down will be added

important: set showDropDown=False in DataValidation function formula1 - must have str type with "" added so the following formatting can be used: formula = '"' + formula + '"'

Regards

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Karol
  • 1
  • 1
-1

Your best bet is going through the COM.

http://oreilly.com/catalog/pythonwin32/chapter/ch12.html

From there, you have all the options available to you in Office's native Visual Basic -- including (at the very least) the ability to send clicks and keypresses to various objects in the window.

Ishpeck
  • 2,001
  • 1
  • 19
  • 21