Configure text alignment in a worksheet cell in Java

Hi I am using Aspose Cells for Java. The problem description is below:


I am using a template for Excel Creation. There is a cell having a Image and Text below it. I am using setVerticalAlignment method to style the text to bottom but it is not working.

Can anybody help ??

Hi,


Thanks for providing us some details.

Could you paste your sample JAVA program (runnable) with template file(s) to reproduce the issue on our end, we will check it soon.

Thank you.

Hi Amzad. I have attached the excel file as template. In this file the cell A5 contains a image and text. I want to move the text somewhat down by giving some absolute position from the top. I tried to align the text also but that is not working.


I have written only the relevant code for this purpose.

Code :

Workbook book = new Workbook(templatePath);

Worksheet sheet = book.getWorksheets().get(0);

Cells cells = sheet.getCells();

cells.getCell(4,0).getStyle().setVerticalAlignment(TextAlignmentType.BOTTOM);

Hi,


Thanks for the template file and sample code segment.

Please change your code segment to:
e.g
Sample code:

Worksheet sheet = book.getWorksheets().get(0);
Cells cells = sheet.getCells();
Style style = cells.get(4,0).getStyle();
style.setVerticalAlignment(TextAlignmentType.BOTTOM);
cells.get(4,0).setStyle(style);

Please create a Style object with your desired formatting and always use Cell.getStyle() and Cell.setStyle() methods to specify style to the cell.

See the document for your reference:

Let us know if you still have any issue.

Thank you.

Thanks Amjad. It worked.

I also have one more requirement like can we absolute position of text inside a cell. Like giving the height of text from top of the cell. I searched on net but could not find anything. Is there any API of Aspose Cells Java available for this purpose.


Hi,


Good to know that the suggested code works for your needs.
Regarding specifying absolute position of text inside a cell (like giving the height of text from top of the cell) I am not sure if there is any options/feature available in MS Excel either (you may specify the position of the shapes though by try using Shape.UpperDeltaY/X attribute(s) in some proportional to row height and column width, etc.). Also, you may set indentation (indent level) while formatting cell contents but there may not be any option to set the absolute position of the inserted text from top of the cell. If you know any such feature in MS Excel, let us know with details with steps involved, we will check it soon.

Thank you.