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

Free Support Forum - aspose.com

How to ApplyStyle or formatting to a row/column or cells in .NET

we are using Aspose.Cells for .NET (.net4.0 dll).
I’m using Apose inside powershell.
As an overview:
We are reading a text-file (plain texdt, separator is TAB.
After reading, I try to apply new a style for the header row.
The new Format is not applied.
(When saving the file as xlsx, all ma other data-m,anipulation are done.)
Here is what I’m doing:

#=====>> loadoptions for loading IPS-Text file
[Aspose.Cells.TxtLoadOptions]$TxtLoadOptions=New-Object Aspose.Cells.TxtLoadOptions;
#<<===== loadoptions for loading IPS-Text file

$wb = new-object Aspose.Cells.Workbook($FilenameIn,$TxtLoadOptions);

#=====>> Style & StyleFlags
#$Style = $wb.CreateStyle();

$styleFlag = New-Object Aspose.Cells.StyleFlag
$styleFlag.HorizontalAlignment = $true;
$styleFlag.VerticalAlignment = $true;
$styleFlag.ShrinkToFit = $true;
$styleFlag.Borders = $true;
$styleFlag.FontColor = $true;
#<<===== Style & StyleFlags

#=====>> creating 2. sheet as table
#$wb.Worksheets.Add(“Pavis Table”);
[Aspose.Cells.Tables.ListObjectCollection] $listObjects = $wb.Worksheets[1].ListObjects;
$listObjects.Add(0, 0, $maxR, $HLastCol, $true);
$ws1.AutoFitRows(0, $maxR);
#<<===== creating 2. sheet as table

$ws0.AutoFitRows(0, $maxR);


Your code looks not compatible when comparing Style with its relevant StyleFlag attributes. You define Style and specify Style attributes. But you do not set the corresponding Boolean attributes for StyleFlag object and vice versa. For example, you only use relevant StyleFlag.FontColor as true. However, what you set for the Style is font size, name and size. This is wrong. Similarly you set the Boolean attributes for alignments, borders, etc. but there are no corresponding attributes (defined) for Style object. Please fix all these issues and then try your scenario/case again, it should work fine.

Moreover, please see the document with examples on formatting rows and columns for your complete reference.

If you still find any issue, kindly do provide sample code (runnable) with template Excel file(s) to reproduce the issue, we will check it soon.

PS. please zip the Excel file(s) prior attaching.

1 Like