Hi,
Thanks for your posting and using Aspose.Cells.
The space (trim end) occurs because of number format. If you change the number format in such a way that end space does not occur, then Aspose.Cells will return you string value according to your applied format.
Please see the following code, its
source excel file and its console output. The console output explains that there was an end space in cell A1 but after applying the custom format, there is no space. Then it prints the first 20 cells and none of them has end space.
Java
Workbook wb = new Workbook(dirPath + “sample.xlsx”);
Worksheet ws = wb.getWorksheets().get(0);
Cell cell = ws.getCells().get(“A1”);
String strValueBefore = cell.getStringValue();
//Apply custom format on entire column
StyleFlag flag = new StyleFlag();
flag.setNumberFormat(true);
String customFormat = “”$"#,##0.00;\("$"#,##0.00\)";
Style st = wb.createStyle();
st.setCustom(customFormat);
ws.getCells().getColumns().get(0).applyStyle(st, flag);
//Now again read the cell value
cell = ws.getCells().get(“A1”);
String strValueAfter = cell.getStringValue();
//Value after does not have last space
if(strValueBefore.compareTo(strValueAfter + " “)==0)
{
System.out.println(“Value After has no end space.”);
}
//Print the first 20 cells
for(int i=0; i<20; i++)
{
Cell c = ws.getCells().get(i, 0);
System.out.println(c.getStringValue()+”—");
}
Console Output
<span style=“color: rgb(255, 0, 0); font-family: “Courier New”; font-size: small;”>Value After has no end space.
$18.00—
$93.00—
$54.00—
$55.00—
$73.00—
$4.00—
$12.00—
$33.00—
$19.00—
$4.00—
$73.00—
$88.00—
$21.00—
$10.00—
$93.00—
$13.00—
$74.00—
$53.00—
$54.00—
$2.00—