XlsFile.SetCellFromString Method
Converts a string to the best datatype, and the enters it into a cell.
Remarks
When using ExcelFile.SetCellValue(Int32, Int32, Object) to set a cell value, you have to know the datatype you want to enter. That is, if you have a string s = "1/1/2002" and call SetCellValue(1, 1, s); the cell A1 will end up with a string "1/1/2002" and not with a date. The same if you have a string holding a number.
SetCellFromString tries to solve this problem. When you call SetCellFromString(1, 1, s) it will look:
- If s contains a valid number: If it does, it will enter the number into the cell, and not the string s
- If s contains a boolean: If s equals the words "TRUE" or "FALSE" (or whatever you define on the constants TxtTrue and TxtFalse) it will enter the boolean into the cell
- If s contains a date: If s is a valid date (according to your windows settings, or with a list of allowed date/time formats) it will enter a number into the cell and format the cell as a date. (see 'Date cells' in the Api Developer Guide)
- In any other case, it will enter the string s into the cell.
Syntax
Namespace: FlexCel.XlsAdapter
public override void SetCellFromString(Int32 sheet, Int32 row, Int32 col, TRichString value, Int32 XF, String[] dateFormats)
Parameters
<-> | Parameter | Type | Description |
---|---|---|---|
sheet | Int32 | Sheet where the cell is (1 based) | |
row | Int32 | Cell Row (1 based) | |
col | Int32 | Cell Column (1 based) | |
value | TRichString | Value to enter into the cell. | |
XF | Int32 | New XF of the cell. It can be modified, i.e. if you enter a date, the XF will be converted to a Date XF. | |
dateFormats | String[] | A list of formats allowed for dates and times. Windows is a little liberal in what it thinks can be a date, and it can convert things like "1.2" into dates. By setting this property, you can ensure the dates are only in the formats you expect. If you leave it null, we will trust "DateTime.TryParse" to guess the correct values. |