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

Free Support Forum - aspose.com

Font name and size not being applied to columns

The following code is working for applying alignments and wrapping. But the font name and sizing is not changing. I am using a template .xlsx file as a source and the template’s fonts and sizes are still present on the output file. Data is being imported to multiple sheets in the workbook and this formatting is applied as a final step.

'Create styles for text and numeric values
Dim styleTxtIdx As Int32 = wbAspose.Styles.Add()
Dim styleTxt As Style = wbAspose.Styles(styleTxtIdx)
Dim styleTxtFlag As New StyleFlag()
styleTxt.HorizontalAlignment = TextAlignmentType.Left
styleTxt.VerticalAlignment = TextAlignmentType.Top
styleTxtFlag.HorizontalAlignment = True
styleTxtFlag.VerticalAlignment = True
styleTxt.Font.Name = “Arial”
styleTxtFlag.FontName = True
styleTxt.Font.Size = 10
styleTxtFlag.FontSize = True

Dim styleNumIdx As Int32 = wbAspose.Styles.Add()
Dim styleNum As Style = wbAspose.Styles(styleNumIdx)
Dim styleNumFlag As New StyleFlag()
styleNum.HorizontalAlignment = TextAlignmentType.Right
styleNum.VerticalAlignment = TextAlignmentType.Top
styleNumFlag.HorizontalAlignment = True
styleNumFlag.VerticalAlignment = True
styleNum.Font.Name = “Arial”
styleNumFlag.FontName = True
styleNum.Font.Size = 10
styleNumFlag.FontSize = True

Dim maxColumn As Int16 = sheet.Cells.MaxDataColumn()

For c = 0 To maxColumn
sheet.AutoFitColumn(c, 1, maxRow)
Catch ex As Exception
Debug.Print("AutoFitColumn FAILED on sheet " & sheet.Name & " column " & c.ToString() & " --> " & ex.ToString())
End Try
If sheet.Cells.GetColumnWidth© > 70 Then
styleTxt.IsTextWrapped = True
styleTxtFlag.WrapText = True
sheet.Cells.SetColumnWidth(c, 70)
End If
If sheet.Cells(2, c).Type = CellValueType.IsNumeric Then
sheet.Cells.ApplyColumnStyle(c, styleNum, styleNumFlag)
sheet.Cells.ApplyColumnStyle(c, styleTxt, styleTxtFlag)
End If
totalColumnWidthInch += sheet.Cells.GetColumnWidthInch©
If (sheet.Cells.GetColumnWidthInch© < 2) Then
smallColumnCount += 1
availableWidthInch = availableWidthInch - sheet.Cells.GetColumnWidthInch©
End If

(Using Aspose Cells version

I set all sheets in the template file to “Arial” font size 10 but I am still getting “Calibri” size 11 on the output file.

Am I missing something in how to apply the font properties?


This message was posted using Page2Forum from Aspose.Cells for .NET - Documentation


<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Well, I tried your scenario abit and did not find any issue with the attached latest version of Aspose.Cells. Please try the attached latest version and if you still face any issue, please create a sample application with your template file to reproduce the issue and post it here. We will check it soon.

Thank You & Best Regards,