I've to write a huge Excel file and the optimized writer in openpyxl is what I need.
The question is:
is it possibile to set style and format of cells when using optimized writer? Style is not so important (I would only like to highlight column headers), but I need the correct number format for some columns containing currency values.
I saw that ws.cell()
method is not available when using optimized writer, so how to do it?
Thank you in advance for your help!
Openpyxl write to a cell There are two basic ways to write to a cell: using a key of a worksheet such as A1 or D3, or using a row and column notation with the cell method. In the example, we write two values to two cells. Here, we assing a numerical value to the A1 cell.
As I can't comment, I'll post an update to Dean's answer here:
openpyxl's api (version 2.4.7) has changed slightly so that it should now read:
from openpyxl import Workbook
wb = Workbook( write_only = True )
ws = wb.create_sheet()
from openpyxl.writer.dump_worksheet import WriteOnlyCell
from openpyxl.styles import Font
cell = WriteOnlyCell(ws, value="highlight")
cell.font = Font(name='Courier', size=36)
cols=[]
cols.append(cell)
cols.append("some other value")
ws.append(cols)
wb.save("test.xlsx")
Hope it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With