NPOI DataFormat

不想你离开。 提交于 2019-12-03 14:24:58

It looks like the problem has something to do with creating new formats that match built-in formats. I changed my lazy-loading method to use the built-in format if available, and the cell formats in my final XLS are all correct now.

if( !_cellStyleCache.ContainsKey ( dataFormat ) )
{
    var style = workbook.CreateCellStyle ();

    // check if this is a built-in format
    var builtinFormatId = HSSFDataFormat.GetBuiltinFormat ( dataFormat );

    if( builtinFormatId != - 1)
    {
        style.DataFormat = builtinFormatId;
    }
    else
    {
        // not a built-in format, so create a new one
        var newDataFormat = workbook.CreateDataFormat ();
        style.DataFormat = newDataFormat.GetFormat ( dataFormat );
    }

    _cellStyleCache[dataFormat] = style;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!