Openpyxl setting number format
This answer works with openpyxl 2.0. (The previously accepted answer does not.)
The number_format
can be changed directly.
The given example becomes:
from openpyxl import Workbook
wb = Workbook()
ws = wb.create_sheet(title='testSheet')
_cell = ws.cell('A1')
_cell.number_format = '0.00E+00'
Note: this answer worked with earlier versions of openpyxl, but does not work with openpyxl 2.0
This is how to do it:
_cell.style.number_format.format_code = '0.00E+00'
To directly format cells using openpyxl version 3 (v3.0.9), the following code was required:
from openpyxl import Workbook
wb = Workbook()
ws = wb.create_sheet(title='testSheet')
_cell = ws['A1']
_cell.number_format = '0.00E+00'
The cell can be formatted directly as follows:
ws['A1'].number_format = '0.00E+00'
The documents show the various number formats available, and there are quite a few: https://openpyxl.readthedocs.io/en/stable/_modules/openpyxl/styles/numbers.html