mashingan / excelin

Create and read Excel file purely in Nim
MIT License
51 stars 1 forks source link

question - how can I perform a "flat" background color fill? #7

Closed mantielero closed 1 year ago

mantielero commented 1 year ago

I see the pattern and gradient arguments in fillStyle. But how can I do a normal flat background?

mashingan commented 1 year ago

There's patternFillStyle that's accepting fgColor. I didn't make the bgColor public because I didn't see its effect when assigning its color while leaving the fgColor default (no color). Hence the patternFillStyle only accepts fgColor argument.

If you can see its differences, please do share the sceenshoots and if possible, please PR to make the bgColor field public.

mantielero commented 1 year ago

Exploring the XML content within a .xlsx file, I came up with the following (which seems to work):

import excelin
import std/colors

let (excel, sheet) = newExcel()
let row1 = sheet.row 1
row1["A"] = "prueba"
row1.style("A",
    fill = fillStyle(
        pattern = patternFillStyle(patternType = ptSolid, fgColor = $colRed)
    )
)
excel.writeFile "test.xlsx"

Regards

mashingan commented 1 year ago

You didn't have to check the XML content though if you did carefully read this example https://github.com/mashingan/excelin#cell-styling

mantielero commented 1 year ago

I tend to disagree.

Searching in the page for the words ptSolid and solid shows no results. I don't think it is obvious for the library user to know that a flat color requires to set the pattern to ptSolid.

I think it would be better to make an explicit example because it is the most common use case for headers.

In any case, thanks a lot for your amazing library.

mashingan commented 1 year ago

I think it would be better to make an explicit example because it is the most common use case for headers.

Appreciated for the input, I'll refine the examples more to be explicit on the available APIs.
I just assumed people could immediately look for the docs, but it's definitely better to be explicit. Thank you.