1

I am trying to set a data type for a cell in CLosedXML, however the answers I have found about my problem all rely on Cell.SetDataType(x) or Cell.DataType = x and both of them seem to be impossible for me for some reason.

Some pages with answers I found:

https://codingjump.com/posts/closedxml-openxml-setting-data-type-for-cell

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

https://github.com/ClosedXML/ClosedXML/wiki/Data-Types

And ALL OF THEM answer as if my problem does not exist for them.

Whenever I attempt to call Cell.SetDatatype(XLDataType.Text) I get the following error:

Error   CS1061  'IXLCell' does not contain a definition for 'SetDataType' and no accessible extension method 'SetDataType' accepting a first argument of type 'IXLCell' could be found (are you missing a using directive or an assembly reference?)    

And whenever I attempt to use Cell.DataType = XLDataType.Text I get this:

Error   CS0200  Property or indexer 'IXLCell.DataType' cannot be assigned to -- it is read only 

How would I set a cell's data type if it is read only?

Kotyo
  • 15
  • 4

1 Answers1

1

With version 0.100 you don't need to set a datatype for a cell, because the type of the cell value will be used. The pages you found are for older versions (page 2 has been updated now).

From the migration guide:

SetDataType methods removed
Method SetDataType has been removed from all interfaces (IXLCell, IXLColumn, IXLColumns, IXLRange …). There is no replacement, if you need to reinterpret existing data, do it in application code and set a new value with a specific type.

Raidri
  • 17,258
  • 9
  • 62
  • 65
  • My issue is that I have a dropdown list that has ratios as options 1:2, 3:4, 16:9, 1:87, and it works fine in local excel but when I open the document to edit it in the online office app, it automatically converts the ratios to time where possible, or divides the numbers where it cannot convert it to time. 1:2 becomes 01:02, 1:87 becomes 0.01149425287 – Kotyo Jul 04 '23 at 08:43
  • I apologize for the confusion, the value I needed to change was not Cell.DataType, it was Cell.Style.NumberFormat – Kotyo Jul 04 '23 at 12:08