XLSX.jl icon indicating copy to clipboard operation
XLSX.jl copied to clipboard

Feature request: creating & applying cell styles and conditional formatting

Open jvkerckh opened this issue 7 years ago • 6 comments

I'm currently working on a large project in Julia, and a part of it is generating Excel reports. Ideally, these reports should mark anomalous results by different text & background colour such that it's easy to see at a glance if everything is as expected or where things went wrong. In particular, I'm looking for a way to do the following 3 things from Julia:

  1. create a cellstyle (font + text/background colour) for use in the generated Excel file;
  2. assign a cellstyle to a specific cell; and
  3. create a conditional formatting and apply it to specific cells.

Would it be possible to provide this functionality in a reasonably intuitive manner?

jvkerckh avatar Oct 08 '18 08:10 jvkerckh

IS possible fomating cells ? How to add outside borders, to change format of numbers etc.. ? Paul

programistawpf avatar Apr 28 '19 07:04 programistawpf

Currently there is a way, but it is not intuitive. I also don't know how to do it properly.

I'm planning adding this feature, but I'll have to do a major rewrite of this package. And unfortunately I have other priorities at this time.

felipenoris avatar Apr 28 '19 15:04 felipenoris

I see, maybe pelse on sample , I can try more , ! Paul

programistawpf avatar Apr 29 '19 14:04 programistawpf

Just leaving an example here - this API is obviously not ideal, but this works for setting the numeric format for a particular type

# at top level
const num_fmt = Ref{Int64}(0)
XLSX.default_cell_format(ws::XLSX.Worksheet, ::Float64) = XLSX.get_num_style_index(ws, num_fmt[])

# ... where file is actually written
outfile = XLSX.open_empty_template()
num_fmt[] = XLSX.styles_add_numFmt(outfile.workbook, "#,##0")
# output steps ... 
XLSX.writexlsx("test.xlsx", outfile)

chris-b1 avatar Jul 24 '20 17:07 chris-b1

Would it be possible to take examples from how similar Python packages, such as openpyxl accomplish this? For example: https://openpyxl.readthedocs.io/en/stable/formatting.html

Boxylmer avatar Apr 06 '21 08:04 Boxylmer

Just also adding to this conversation as such functionality does seem possible given what pandas has implemented: https://stackoverflow.com/questions/26265403/easiest-way-to-create-a-color-gradient-on-excel-using-python-pandas

TheCedarPrince avatar May 07 '21 04:05 TheCedarPrince