@Prem_Parmar
Summary
Cell.setValue(Object) – from version 21.11 the method tries to auto‑detect the data type of a String.
- If the string can be parsed as a number (e.g.,
"123,456"), the cell is populated with a numeric value.
Cell.putValue(Object) – stores the value exactly as‑is, without any conversion. The cell type becomes Text (type DataType.TEXT).
So, after the 21.11 release setValue("123,456") is treated as a number, whereas older versions stored it as plain text.
How to keep the value as text
1. Use putValue
import com.aspose.cells.*;
Workbook wb = new Workbook();
Worksheet ws = wb.getWorksheets().get(0);
Cell cell = ws.getCells().get("A1");
// This will *not* try to parse the string → stays as TEXT
cell.putValue("123,456");
2. Force Text format with setValue
If you prefer setValue (e.g., you need the overload that also updates the style), you can force the cell to be treated as text:
Cell cell = ws.getCells().get("A1");
// Set the number format to Text (@"")
Style style = cell.getStyle();
style.setNumber(0); // 0 = General; for explicit text use "@"
style.setCustom("@"); // explicit Text format
cell.setStyle(style);
// Now set the value – it will be stored as TEXT
cell.setValue("123,456");
Note: The custom number format "@" tells Aspose.Cells (and Excel) to keep the content as a string.
3. Disable auto‑conversion globally (if required)
// Turn off automatic conversion for the whole workbook
Workbook wb = new Workbook();
wb.getSettings().setConvertNumericStringToNumber(false);
After this setting, all setValue(String) calls will store the string as text, regardless of its numeric appearance.
Why the behavior changed
The change is documented in the 21.11 release notes:
“Cell.setValue(String) now automatically converts numeric‑looking strings to numbers, following the current culture settings.”
Reference: Aspose.Cells for Java 21.11 Release Notes
Recommended approach
- If you always need the value to stay as text → use
putValue (simplest).
- If you need to apply a style at the same time → set the cell’s number format to
"@" first, then call setValue.
Both approaches work across all supported Aspose.Cells versions.
Useful Links
If you have any further questions or need assistance with a specific scenario, feel free to ask!