Free Support Forum - aspose.com

Applying style at cell Level

Hi All,

In older version of aspose , we will apply style at cell Level like this..

sheet.Cells[0, col].Style.HorizontalAlignment = TextAlignmentType.Center;

But i am using aspose version 4.9.1.0 .. in this I am getting one built in function SetStyle().

Now my question is If I want to apply the style as I mentioned above..like

how to do achieve this in single statement as above..

sheet.Cells[0,col].SetStyle(..... continue here..

Please provide the code for this..

Thanks,

Hi Jack,

Please go through the information given in the link below. This will make you understand why this Style Get/ Set methods have been introduced.

http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/evaluating-cell-getstyle-setstyle-methods-against-cell-style-property.html

You can use following lines of code to Get/ Set cell style.

Code snippet:
Dim workbook As New Workbook()
Dim sheet As Worksheet = workbook.Worksheets(0)
Dim cellName As String = "A1"
Dim s As Style = sheet.Cells(cellName).GetStyle()
s.HorizontalAlignment = TextAlignmentType.Center
sheet.Cells(cellName).SetStyle(s)
workbook.Save("e:\test\outcellformat1.xls")

For further reference:
http://www.aspose.com/documentation/java-components/aspose.cells-for-java/adding-borders-to-cells.html

Thanks,