mirror of
https://github.com/iOfficeAI/OfficeCLI
synced 2026-04-21 13:37:23 +00:00
fix(xlsx): honor explicit cell type= directive
Explicit type=string now forces an inline-string cell even when the value is numeric-looking (e.g. value=123), instead of silently storing a number. Explicit type=number with a non-numeric value now throws ArgumentException instead of silently storing as string.
This commit is contained in:
parent
dd2d010191
commit
74613df6b5
1 changed files with 19 additions and 0 deletions
|
|
@ -1436,6 +1436,25 @@ public partial class ExcelHandler
|
|||
cell.CellValue = new CellValue(cellValue);
|
||||
cell.DataType = new EnumValue<CellValues>(CellValues.String);
|
||||
}
|
||||
else if (explicitTypeIsString)
|
||||
{
|
||||
// R15-2: honor explicit type=string even for
|
||||
// numeric-looking literals. Without this, Excel
|
||||
// renders 123 as a number despite user intent.
|
||||
cell.CellValue = new CellValue(cellValue);
|
||||
cell.DataType = new EnumValue<CellValues>(CellValues.String);
|
||||
}
|
||||
else if (explicitTypeIsNumber)
|
||||
{
|
||||
// R15-2: honor explicit type=number — refuse
|
||||
// non-numeric values rather than silently storing
|
||||
// as string.
|
||||
if (!double.TryParse(cellValue, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out _))
|
||||
throw new ArgumentException(
|
||||
$"Cannot store '{cellValue}' as number; use type=string or remove type=");
|
||||
cell.CellValue = new CellValue(cellValue);
|
||||
cell.DataType = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
cell.CellValue = new CellValue(cellValue);
|
||||
|
|
|
|||
Loading…
Reference in a new issue