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

Free Support Forum - aspose.com

Inconsistent cell style API call results

In my code I query border style for multiple times, and the first time the result is incorrect, but the 2nd iteration gets it right. It seems like a bug to me. Please check the attached file and the sample code that reproduces the issue:


public class InconsistentCellStyleIssue :IssueTestBase
{
[FactDebugOnly]
public void Test()
{
var workbook = new Workbook(GetFullPath(“sample.xlsx”));

var styles = Enumerable.Empty().Select(s => new {Name = s, Style = s}).ToList();

var range = workbook.Worksheets[“ByCostCenter”].Cells.MaxDisplayRange;
var cells = range.Worksheet.Cells;

for (var i = 0; i < 2; i++) // 2 iterations
{
for (var row = range.FirstRow; row < range.FirstRow + range.RowCount; row++)
{
if (cells.Rows[row].IsHidden) continue;

for (var col = range.FirstColumn; col < range.FirstColumn + range.ColumnCount; col++)
{
if (cells.Columns[col].IsHidden) continue;

var cell = cells[row, col];
var style = GetCellStyle(cell);
var cellStyle = Map(style);
styles.Add(new {cell.Name, Style = cellStyle});
}
}
}



var issues = styles.Distinct()
.GroupBy(s => s.Name, s => s.Style)
.Where(g => g.Count() > 1)
.ToDictionary(g => g.Key, g => string.Join(" -> “, g));

issues.Should().BeEmpty(); // But contains{[A6, Thin, Thin -> Thick, Thin]}

// var l1 = GetCellStyle(workbook.Worksheets[“ByCostCenter”].Cells[“A6”]).Borders[BorderType.BottomBorder].LineStyle;
// var l2 = GetCellStyle(workbook.Worksheets[“ByCostCenter”].Cells[“A6”]).Borders[BorderType.BottomBorder].LineStyle;
// l1.Should().Be(l2);
}

private static Style GetCellStyle(Cell cell)
{
var style = cell.GetDisplayStyle();

if (style.HorizontalAlignment == TextAlignmentType.General &&
(cell.Type == CellValueType.IsNumeric || cell.Type == CellValueType.IsDateTime))
style.HorizontalAlignment = TextAlignmentType.Right;

return style;
}

private static string Map(Style style)
{
return string.Join(”, “,
new[] {BorderType.BottomBorder, BorderType.TopBorder}.Select(
bt => style.Borders[bt].LineStyle.ToString()));
}
}


var issues = styles.Distinct()
.GroupBy(s => s.Name, s => s.Style)
.Where(g => g.Count() > 1)
.ToDictionary(g => g.Key, g => string.Join(” -> “, g));

issues.Should().BeEmpty(); // But contains{[A6, Thin, Thin -> Thick, Thin]}
}

private static Style GetCellStyle(Cell cell)
{
var style = cell.GetDisplayStyle();

if (style.HorizontalAlignment == TextAlignmentType.General &&
(cell.Type == CellValueType.IsNumeric || cell.Type == CellValueType.IsDateTime))
style.HorizontalAlignment = TextAlignmentType.Right;

return style;
}

private static string Map(Style style)
{
return string.Join(”, ",
new[] {BorderType.BottomBorder, BorderType.TopBorder}.Select(
bt => style.Borders[bt].LineStyle.ToString()));
}
}

Hi,


Thanks for the template file and sample code with details.

After an initial test, I observed the issue as you mentioned by using your sample code segment with your template file. I found an inconsistent cell style API call results regarding borders. When, we query border style for multiple times (e.g 2 times), I confirmed the first time the result is incorrect, but for the 2nd iteration, it gives correct results. For example, cells A6 to O6, I found border styles (bottom, top):
Thin, Thin (First time which is incorrect) Vs Thick, Thin (Second time which is correct result) for the same cell(s):
e.g
Sample code:

public void Test()<o:p></o:p>

{

var workbook = new Workbook("e:\\test2\\sample.xlsx");

var styles = Enumerable.Empty<string>().Select(s => new {Name = s, Style = s}).ToList();

var range = workbook.Worksheets["ByCostCenter"].Cells.MaxDisplayRange;

var cells = range.Worksheet.Cells;

for (var i = 0; i < 2; i++) // 2 iterations

{

for (var row = range.FirstRow; row < range.FirstRow + range.RowCount; row++)

{

if (cells.Rows[row].IsHidden) continue;

for (var col = range.FirstColumn; col < range.FirstColumn + range.ColumnCount; col++)

{

if (cells.Columns[col].IsHidden) continue;

var cell = cells[row, col];

var style = GetCellStyle(cell);

var cellStyle = Map(style);

styles.Add(new {cell.Name, Style = cellStyle});

}

}

}

var issues = styles.Distinct()

.GroupBy(s => s.Name, s => s.Style)

.Where(g => g.Count() > 1)

.ToDictionary(g => g.Key, g => string.Join(" -> ", g));

}

private static Style GetCellStyle(Cell cell)

{

var style = cell.GetDisplayStyle();

if (style.HorizontalAlignment == TextAlignmentType.General &&

(cell.Type == CellValueType.IsNumeric || cell.Type == CellValueType.IsDateTime))

style.HorizontalAlignment = TextAlignmentType.Right;

return style;

}

private static string Map(Style style)

{

return string.Join(", ",

new[] {BorderType.BottomBorder, BorderType.TopBorder}.Select(

bt => style.Borders[bt].LineStyle.ToString()));

}


I have logged a ticket with an id "CELLSNET-44911" for your issue. We will look into it soon.

Once we have an update on it, we will let you know here.

Thank you.
Hi,

Thanks for using Aspose.Cells.

This is to inform you that we have fixed your issue CELLSNET-44911 now. We will soon provide the fix after performing QA and including other enhancements and fixes.

Hi,


Please try our latest version/fix: Aspose.Cells for .NET v16.11.2

your issue “CELLSNET-44911” should be fixed in it.

Let us know your feedback.

Thank you.

The issues you have found earlier (filed as CELLSNET-44911) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.