Aspose Cells Java : Trying to set all cells of a column to format: Number

Hi,

I am trying to set all cells of a column to format: Number.
My code:

import com.aspose.cells.*;

public class asposeSetColumnTypeNumber {

public static void main(String[] args) throws Exception {


	Workbook wb = new Workbook();
	Worksheet ws = wb.getWorksheets().add("temp");
	
	Style columnStyle = ws.getCells().getColumns().get(0).getStyle();
	StyleFlag columnStyleFlag = new StyleFlag();
	columnStyleFlag.setNumberFormat(true);
	ws.getCells().getColumns().get(0).applyStyle(columnStyle, columnStyleFlag);

	wb.save("C:\\Users\\sandipan.ghosh\\Desktop\\Test.xlsx");
	System.out.println("Completed.");
}

}

But the code doesn’t work. What am i doing wrong?

@sandipanghosh111,

Thanks for the code segment.

What numbers formatting you are applying? Seeing your sample code, well, you are missing the line on what style/formatting you are applying as I could not spot it. So, you should specify your desired numbers formatting for the style, see the line in bold for your reference:
e.g
Sample code:


Style columnStyle = ws.getCells().getColumns().get(0).getStyle();
columnStyle.setCustom(“0.00”);//This will apply the numbers formattings in such a way that it will set two decimal points for each value
StyleFlag columnStyleFlag = new StyleFlag();
columnStyleFlag.setNumberFormat(true);
ws.getCells().getColumns().get(0).applyStyle(columnStyle, columnStyleFlag);

Hope, this helps a bit.

Thanks. It worked.

@sandipanghosh111,

Good to know that your issue is sorted out by the suggested line of code. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.