Re: borders reported by GetStyle vs. GetDisplayStyle

Why is there a discrepancy between the borders settings reported by GetStyle vs GetDisplayStyle?


The output of the following program is:

Style A1 Bottom border=Thin
Display Style A1 Bottom border=Thin
Style A2 Top border=Thin
Display Style A2 Top border=None
Style A3 Top border=None
Display Style A3 Top border=None
Done!


Which one should I use if I want to read the border info? I would say GetStyle because it is in sync with what Excel shows.

Thank you

Code:

using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using Aspose.Cells;
using Aspose.Cells.Pivot;


namespace TestAspose
{
class Program
{
static void Main(string[] args)
{
Procedure13();
Console.WriteLine(“Done!”);
Console.ReadKey();
}

private static void Procedure13()
{

Workbook workbook = new Workbook(@"…\borders.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
Style a1Style = worksheet.Cells[“A1”].GetStyle();
Style a2Style = worksheet.Cells[“A2”].GetStyle();
Style a3Style = worksheet.Cells[“A3”].GetStyle();
Style a1DisplayStyle = worksheet.Cells[“A1”].GetDisplayStyle();
Style a2DisplayStyle = worksheet.Cells[“A2”].GetDisplayStyle();
Style a3DisplayStyle = worksheet.Cells[“A3”].GetDisplayStyle();
Console.WriteLine(“Style A1 Bottom border={0}”, a1Style.Borders[BorderType.BottomBorder].LineStyle);
Console.WriteLine(“Display Style A1 Bottom border={0}”, a1DisplayStyle.Borders[BorderType.BottomBorder].LineStyle);
Console.WriteLine(“Style A2 Top border={0}”, a2Style.Borders[BorderType.TopBorder].LineStyle);
Console.WriteLine(“Display Style A2 Top border={0}”, a2DisplayStyle.Borders[BorderType.TopBorder].LineStyle);
Console.WriteLine(“Style A3 Top border={0}”, a3Style.Borders[BorderType.TopBorder].LineStyle);
Console.WriteLine(“Display Style A3 Top border={0}”, a3DisplayStyle.Borders[BorderType.TopBorder].LineStyle);

}
}
}

Hi,


Well, the top border of A2 is actually the bottom border of A1 cell. The Cell.GetDisplayStyle method is specifically used to get the display style of the cell if the cell is conditionally formatted.

I think for your current needs, you may use Cell.GetStyle method.

Thank you.