How to set a data type for a column with ClosedXML?

后端 未结 1 906
故里飘歌
故里飘歌 2021-01-04 09:16

I see a lot of examples in documentation where data type for a cell is set:

ws.Cell(1, 1).SetDataType(XLCellValues.Text);

But when I try to

相关标签:
1条回答
  • 2021-01-04 09:37

    ClosedXML sets the data type for all cells in the column, down to the maximum (row 1 million or so). Use this to only set the data type for the used cells in the column:

    ws.Column(1).CellsUsed().SetDataType(XLDataType.Text);
    

    Furthermore, the data type in ClosedXML is not the same as the cell format in Excel (have a look at the example file from the documentation to see the difference).

    0 讨论(0)
提交回复
热议问题