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

Free Support Forum - aspose.com

How do I change the font of cells containing text in a worksheet ListObject?

I’m using Aspose.Cells version 8.6.0.0 and would like to know how I can change the font to Arial and font size of text in the cells of a worksheet ListObject? Do I need to use listObject.TableStyleType = Aspose.Cells.Tables.TableStyleType.Custom? I can’t find any information on how to use the Custom property. Any help or advice would be appreciated. Thanks!

I’ve tried this C# code but it is not working:


Aspose.Cells.Tables.ListObjectCollection listObjects = worksheet.ListObjects;
foreach (Aspose.Cells.Tables.ListObject listObject in listObjects)
{
Style st = new Style();
st.Font.Name = “Arial”;
StyleFlag stFlag = new StyleFlag();
stFlag.All = true;
listObject.DataRange.ApplyStyle(st, stFlag);
}

Hi,

Thanks for your posting and using Aspose.Cells.

Please download and use the latest version: Aspose.Cells for .NET 8.6.1. It is working fine with your sample code.

I have tested it with the following code and the list object font was changed to Arial. I have attached the source excel file used in this code and output excel file generated by it for your reference.

Please also use the Workbook.CreateStyle() method to create the Style object as shown in the code instead of using Style constructor.

C#
string filePath = @“F:\Shak-Data-RW\Downloads\source.xlsx”;

Workbook workbook = new Workbook(filePath);

Worksheet worksheet = workbook.Worksheets[0];

Aspose.Cells.Tables.ListObjectCollection listObjects = worksheet.ListObjects;

foreach (Aspose.Cells.Tables.ListObject listObject in listObjects)
{
Style st = workbook.CreateStyle();
st.Font.Name = “Arial”;
StyleFlag stFlag = new StyleFlag();
stFlag.All = true;
listObject.DataRange.ApplyStyle(st, stFlag);
}

workbook.Save(“output.xlsx”);

That worked using Aspose.Cells version 8.6.0.0

Style st = workbook.CreateStyle();


Thanks for your help!!!

Hi,

Thanks for your feedback and using Aspose.Cells.

It is good to know that your issue is sorted out. Let us know if you encounter any other issue, we will be glad to look into it and help you further. Have a good day.

Oops. I spoke too quickly. It did not work with Aspose.Cells 8.6.0.0.

Hi,

Thanks for your posting and using Aspose.Cells.

It might be a bug in older version 8.6.0. Could you please also give a try to latest version: Aspose.Cells for .NET 8.6.1 because it worked fine as I have shown in the earlier post and presented you the source and output excel files. Let us know your feedback.