We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to align text in the cell to top and left in aspose.cells java

Hi,


In excel, for a given cell, we can do the align text to top and left on the same cell. I am not sure which method should be used in aspose.cells.

Please give the sample line of code for this.


Thanks.

Hi Esha,


Thank you for contacting Aspose support.

Please note that the textual values (unlike numbers) are aligned top & left by default. However, you may also achieve this with the following piece of code.

Java

//Instantiating a Workbook object
Workbook workbook = new Workbook();

//Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().get(0);

//Accessing the cells of first worksheet
Cells cells = worksheet.getCells();

//Accessing the “A1” cell from the worksheet
Cell cell=cells.get(“A1”);

//Adding some value to the “A1” cell
cell.setValue(“Hello Aspose!”);

Style style = workbook.createStyle();

//Setting the vertical alignment of the text in the “A1” cell
style.setVerticalAlignment(TextAlignmentType.TOP);

//Setting the horizontal alignment of the text in the “A1” cell
style.setHorizontalAlignment(TextAlignmentType.LEFT);

//Apply style onto the cell
cell.setStyle(style);

//Saving the modified Excel file
workbook.save(“D:/output.xlsx”, SaveFormat.XLSX);

If we have misunderstood your requirement then please share your desired results, that you may create manually using MS Excel application. Upon reviewing your desired results, we will be in a better position to mimic the same functionality using Aspose.Cells for Java API.

thanks it is working.

Hi Esha,


Thank you for the confirmation. It is good to know that you are up & running again, Please feel free to contact us back in case you need our further assistance with Aspose APIs.