tfussell / xlnt

:bar_chart: Cross-platform user-friendly xlsx library for C++11+
Other
1.47k stars 409 forks source link

How to ensure a cell has a format and/or style #603

Closed daixtrose closed 2 years ago

daixtrose commented 2 years ago

Maybe I overlooked something in the docs, but I assumed that when creating a new Excel sheet or opening one that the call in cell.cpp#L875 to has_format() would succeed, but this is not the case. It returns false.

style cell::style()
{
    if (!has_format() || !format().has_style())
    {
        throw invalid_attribute();
    }
   // ...

So it seems that asking an existing cell for its style or format needs some preparation. Could you elaborate on how to copy a style/format from an existing cell to another one?

To be more precise: I want to start with a template that has a range of cells formatted as a table and I want to extend that one to an arbitrary number of lines, thereby copying every relevant format or style attribute from the second line of the table.

daixtrose commented 2 years ago

It looks like tables are not supported yet?

tfussell commented 2 years ago

Sorry for the slow response. Unfortunately tables are indeed not yet supported. It seems that tables must use a different kind of styling on cells so the existing code can't easily be used to copy the table style. I'd be happy to provide support for anyone that would like to add table support.