Quantcast
Channel: ClosedXML - The easy way to OpenXML
Viewing all articles
Browse latest Browse all 1877

New Post: Use of custom Table style

$
0
0
After looking at the source code, I can confirm my suspicion regarding the source of the error. While it would be amazing if ClosedXML supported custom table styles, it would likely be beneficial in any case to add some error handling such that existing files with custom-styled tables can be opened. Something like:

XLWorkbook_Load.cs
if (dTable.TableStyleInfo != null)
{
    if (dTable.TableStyleInfo.ShowFirstColumn != null)
        xlTable.EmphasizeFirstColumn = dTable.TableStyleInfo.ShowFirstColumn.Value;
    if (dTable.TableStyleInfo.ShowLastColumn != null)
        xlTable.EmphasizeLastColumn = dTable.TableStyleInfo.ShowLastColumn.Value;
    if (dTable.TableStyleInfo.ShowRowStripes != null)
        xlTable.ShowRowStripes = dTable.TableStyleInfo.ShowRowStripes.Value;
    if (dTable.TableStyleInfo.ShowColumnStripes != null)
        xlTable.ShowColumnStripes = dTable.TableStyleInfo.ShowColumnStripes.Value;
    if (dTable.TableStyleInfo.Name != null)
    {
        XLTableTheme theme;
        if (Enum.TryParse(dTable.TableStyleInfo.Name.Value, out theme))                        
            xlTable.Theme = theme;                        
        else                        
            xlTable.Theme = XLTableTheme.None;                                             
    }
    else
        xlTable.Theme = XLTableTheme.None;
}
In this way the Load will succeed even when a custom style is used on a table in the document.

Viewing all articles
Browse latest Browse all 1877

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>