Hi,
We are using aspose.cells version 7.4.2.0 to implement export and import of the data from excel.
We have a requirement where we need to mark the row in ListObject as BAD. and while importing again detect if row is marked as BAD style and reset the style back to normal row. We could set the style to BAD but existing datetime format(custom) is getting lost and being converted to double.
Any idea, how can preserve the datetime formatting while applying/removing the style?
Below is the code:
MarkRowBAD(rowPos)
{
Style style = this.ExcelWorkbook.Styles.CreateBuiltinStyle(BuiltinStyleType.Bad);
//set the style to all the cells of ListObject
for (int i = 0; i <= (tableObject.EndColumn - tableObject.StartColumn); i++)
{
if (tableObject.DataRange[rowPos, i].Type == CellValueType.IsDateTime)
{
Style currStyle = tableObject.DataRange[rowPos, i].GetStyle();
style.Custom = currStyle.Custom;
}
tableObject.DataRange[rowPos, i].SetStyle(style);
style.Custom = “”;
}
}
Unmark(rowPos)
{
//detect:when style is not set on first and last cell of row return
if ((tableObject.DataRange[rowPos, 0].GetStyle().ParentStyle == null ||
tableObject.DataRange[rowPos, 0].GetStyle().ParentStyle.Name.ToLower() != AposeBuiltInBadStyle.ToLower()) &&
(tableObject.DataRange[rowPos, tableObject.EndColumn-1].GetStyle().ParentStyle == null ||
tableObject.DataRange[rowPos, tableObject.EndColumn - 1].GetStyle().ParentStyle.Name.ToLower() != AposeBuiltInBadStyle.ToLower()))
return;
//get normal Style
Style style = this.ExcelWorkbook.Styles.CreateBuiltinStyle(BuiltinStyleType.Normal);
//remove: set the style to all the cells of table object to normal
for (int i = 0; i <= (tableObject.EndColumn - tableObject.StartColumn); i++)
{
if (tableObject.DataRange[rowPos, i].Type == CellValueType.IsDateTime)
{
Style currStyle = tableObject.DataRange[rowPos, i].GetStyle();
style.Custom = currStyle.Custom;
}
tableObject.DataRange[rowPos, i].SetStyle(style);
style.Custom = “”;
}
}
Grey: I have put this code to handle the formatting of datetime. Is it correct way of doing it?
Also, please correct us we are doing is wrong?
We really appreciate your help.
Thanks,
Nikhil