I love aspose. Usually. But sometimes even the simplest tasks are mindbogglingly impossible that it feels unreal.
Hi,
I have tested your mentioned issue and found it is working fine. I have used the latest:
Aspose.Cells for .NET (Latest Version)
Please see the code below and the source and output file. Please see the screenshot.
C#
string filePath = @“F:\Shak-Data-RW\Downloads\source.xlsx”;
Workbook workbook = new Workbook(filePath);
Worksheet worksheet = workbook.Worksheets[0];
Range rng1 = worksheet.Cells.CreateRange(“A1”, “B8”);
Range rng2 = worksheet.Cells.CreateRange(“D1”, “E8”);
rng2.CopyStyle(rng1);
workbook.Save(filePath + “.out.xlsx”);
Screenshot:
Not quite sure what is happening. The exact same code is not working for me.
Hi,
Please provide us your source sample project replicating this issue along with your sample input file.
Hi.
Hi,
Well, your source range and destination range have different cells area to be copied/formatted, you may try to change your lines of code a bit, i.e.:
string importFile = “Template.xlsx”;
Workbook wbook = new Workbook(importFile);
Worksheet wsheet = wbook.Worksheets[0];
// Copy the format of one cell - create source range
Range srcRange = wsheet.Cells.CreateRange(“A8”, “B10”);
Range destRange = wsheet.Cells.CreateRange(“C8”, “D10”);
//wsheet.Cells.CreateRange(srcRange.FirstRow, srcRange.FirstColumn+1, srcRange.RowCount, 1);
destRange.CopyStyle(srcRange);
DataTable dt = GetDataFromDB();
wsheet.Cells.ImportDataTable(dt, true, 9,0,false);
I have tested and it works fine for your needs.
Thank you.
in excel, if you copy the formatting of a range, and apply it to a bigger range, it just copies itself multiple times. i was expecting the same behaviour.
Hi,