Provide a functionality to to keep style of table cells intact

If you create a table (listobject) with 1 row and format the first row and write n values to the listobject with PutCellValue, the format is used in the first row, but it’s not applied to all the other cells that are added. (as it works with insertrange).
Please provide an option to keep the format (style) for the values inserted.

as a workaround i’m storing the style information of the first cell and applying it to each value i write.
But there is a bug, the formatting always gets applied to the totals row this way, even if the totals row is not the cell i’m using Cell.setStyle() on.
(Please fix this also)

@SimplyLiz
Could you provide sample codes and template file to show your issue?

Hi,

Here is a template + code that should clarify the issues with format pasting and the totals row.

ListObjectCollection listObjects = workbook.Worksheets[0].ListObjects;
      for (int sheetIndex = 0; sheetIndex < report.Workbook.Worksheets.Count; sheetIndex++)
      {
        foreach (ListObject listObject in workbook.Worksheets[sheetIndex].ListObjects)
        {
          int tableWidth = listObject.EndColumn - listObject.StartColumn;
          

          for (int colOffset = 0; colOffset <= tableWidth; colOffset++)
          {

            listObject.PutCellValue(1, colOffset, "ExampleText");
            listObject.PutCellValue(2, colOffset, "ExampleText");
            listObject.PutCellValue(3, colOffset, "ExampleText");
            
            if (listObject.DisplayName.StartsWith("PasteStyle"))
            {
              Style currentStyle = workbook.Worksheets[sheetIndex].Cells[listObject.StartRow+1, listObject.StartColumn + colOffset].GetStyle();

              workbook.Worksheets[sheetIndex].Cells[listObject.StartRow + 1, listObject.StartColumn + colOffset].SetStyle(currentStyle);
              workbook.Worksheets[sheetIndex].Cells[listObject.StartRow + 2, listObject.StartColumn + colOffset].SetStyle(currentStyle);
              workbook.Worksheets[sheetIndex].Cells[listObject.StartRow + 3, listObject.StartColumn + colOffset].SetStyle(currentStyle);
            }

          }
        }
      }

template.zip (10.9 KB)

@SimplyLiz,

Thanks for the template file and sample code.

I noticed the issue you mentioned with format pasting and the totals row. We need to investigate your issue in details. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSNET-53290

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@SimplyLiz
We have no plan to provide such function, please copy style with Cell.setStyle() . MS Excel does not automatically copy style if you fill data in MS Excel too.
Please check whether there is total row with ListObject.ShowTotals property.

Hi,

Sorry i forgot to add the template and only uploaded the result file.

tables.zip (11.8 KB)

Please check whether there is total row with ListObject.ShowTotals property.

What do you mean? in excel it doesn’t matter if you have totals enabled or not, values are added properly when you press tab and the totals row is not overwritten. I need to implement the same behavior as in excel with totals

@SimplyLiz,

We noticed the behavior in MS Excel manually. We will look into it and get back to you soon.

@SimplyLiz,

This is to inform you that your issue (logged earlier as “CELLSNET-53290”) has been resolved now. The fix will be included in our upcoming release (Aspose.Cells v23.6) that we plan to release in the first half of June 2023. You will be notified when the next version is released.

The issues you have found earlier (filed as CELLSNET-53290) have been fixed in this update. This message was posted using Bugs notification tool by johnson.shi