This project has moved. For the latest updates, please go here.

Style Columns based on Model Attributes?

Jan 3, 2013 at 5:35 AM
Edited Jan 3, 2013 at 5:38 AM

I love being able to write a collection to a cell value -- I pull the headers from a corresponding openlistview control, which was configured via custom attributes decorating my model.  In this way I can add or subtract public properties from my collection object and the listview control and the excel export just work.

Except for one little thing:  Excel Formatting.  In my model I have a property, rate, as follows:

        <OLVColumn(DisplayIndex:=2, AspectToStringFormat:="{0:P3}", TextAlign:=HorizontalAlignment.Right, FillsFreeSpace:=True, FreeSpaceProportion:=100)>
        Public Property Rate() As Double

The AspectToStringFormat property indicates percent format.  It would be ideal if the were an equivalent ability in ClosedXML - so I could have something like:

        <OLVColumn(DisplayIndex:=2, AspectToStringFormat:="{0:P3}", TextAlign:=HorizontalAlignment.Right, FillsFreeSpace:=True, FreeSpaceProportion:=100)>
        <CXMLColumn(NumberFormatFormat := "%", StyleAlignmentHorizontal := XLAlignmentHorizontalValues.Right, ColumnWidth:=20)>
        Public Property Rate() As Double      
As it is, my excel export code will have to be manually kept in sync with my model (unless I missed seeing it in the documentation). Any plans to add this feature?
Coordinator
Jan 3, 2013 at 4:22 PM

Can't make that happen. It would require ClosedXML to reference the object list view project.

Jan 3, 2013 at 10:38 PM

The proposed attributes in my example would be independent from object list view's attributes -- I just used it as a model and inspiration.  "CXMLColumn" is my proposed name for a ClosedXML Column Styles Attribute model.  In isolation:

<CXMLColumn(NumberFormatFormat := "%", StyleAlignmentHorizontal := XLAlignmentHorizontalValues.Right, ColumnWidth:=20)>
        Public Property Rate() As Double