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

Free Support Forum - aspose.com

Range Loss Style

Hi,
I try to copy excel range into another excel range,
but the destination range lost the style (background color its not the same of the original range)

In Excel, I get the correct result, doing the copy and paste from two excel files only with the keep source formatting paste options.

I attach the excel file.
TestFile.zip (17.3 KB)

@qwerty12z,

Thanks for your query.

Following sample code can be used to copy the data and formatting as well. Try this code using latest version of Aspose.Cells for .NET 18.8.* and provide your feedback here.

Workbook workbook = new Workbook("TestFile.xlsx");
Workbook destWorkbook = new Workbook();
Worksheet destSheet = destWorkbook.Worksheets[0];
int TotalRowCount = 0;
// Set PasteOptions
PasteOptions pasteOptions = new PasteOptions();
pasteOptions.PasteType = PasteType.Default;
pasteOptions.OnlyVisibleCells = true;

for (int i = 0; i < workbook.Worksheets.Count; i++)
{
    Worksheet sourceSheet = workbook.Worksheets[i];
    Aspose.Cells.Range sourceRange = sourceSheet.Cells.MaxDisplayRange;
    Aspose.Cells.Range destRange = destSheet.Cells.CreateRange(sourceRange.FirstRow + TotalRowCount, sourceRange.FirstColumn,
            sourceRange.RowCount, sourceRange.ColumnCount);

    destRange.Copy(sourceRange, pasteOptions);

    TotalRowCount = sourceRange.RowCount + TotalRowCount;
}

destWorkbook.Save("output.xlsx");

Hi,
The source code supplied to me, does not work, I send you an example, to reproduce the problem.

TestAspose.zip (2.6 MB)

@qwerty12z,

We were able to observe the issue but we need to look into it more. We have logged the issue in our database for investigation and for a fix. Once, we will have some news for you, we will update you in this topic.

This issue has been logged as

CELLSNET-46355 - Style lost while copying the range

@qwerty12z,

Please copy the theme from the template file, it will work fine. See the following sample code:
e.g
Sample code:

    Workbook workbook = new Workbook(dir + "TestFile.xlsx");
            Workbook destWorkbook = new Workbook();
            destWorkbook.CopyTheme(workbook);