You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been trying to figure out how to add number formats to my xlsx files and I seem to be hitting a road block here.
using XLSX
sheet_name ="test_sheet"
xf = XLSX.open_empty_template(sheet_name)
sheet = xf[sheet_name]
wb = XLSX.get_workbook(xf)
# Create a font style
fontattr = XLSX.FontAttribute["b", "name"=> ("val"=>"Calibri"), "sz"=> ("val"=>"12")]
boldfont = XLSX.styles_add_font(wb, fontattr)
boldstyle = XLSX.styles_add_cell_xf(
wb,
Dict("applyFont"=>"true", "fontId"=>"$boldfont"),
)
# This works fine if you open it up in Excel
sheet["A1"] = XLSX.CellValue("This is Bold", boldstyle)
XLSX.writexlsx("./numfmt_issue_working.xlsx", xf)
# Create a number format style
datefmt = XLSX.styles_add_numFmt(wb, "YYYYMMDD")
datestyle = XLSX.styles_add_cell_xf(
wb,
Dict("applyNumberFormat"=>"1", "numFmtId"=>"$datefmt"),
)
# This results in an error when Excel tries to read the file
sheet["A2"] = XLSX.CellValue(42332, datestyle)
XLSX.writexlsx("./numfmt_issue_broken.xlsx", xf)
If you run that snippet it will generate two files. Once the numFmt gets added to the workbook it seems to break compatibility with Excel.
Using Excel for Mac v16.29
The text was updated successfully, but these errors were encountered:
After a bunch of digging, it looks like the <numFmts><numFmts/> tag needs to appear in the xl/styles.xml file before it's referenced in the <cellXfs></cellXfs> block, or else Excel throws a fit about it. I'll write a fix and submit it in a bit.
I've been trying to figure out how to add number formats to my xlsx files and I seem to be hitting a road block here.
If you run that snippet it will generate two files. Once the
numFmt
gets added to the workbook it seems to break compatibility with Excel.Using Excel for Mac v16.29
The text was updated successfully, but these errors were encountered: