Getting all the format settings from an excel file and apply them to a new one

hi!


i want to be able to copy the formatting(colors, chart properties, cell formatting, scrollbar visibility etc.) of an existing excel file to a new file and change only the data (filled in from a db or an array in code) in the new one. i want to avoid setting the the formatting of the file using code like this:

cells.ApplyStyle(Style, StyleFlag);

how can this be done?

Hi Yashali,


Thank you for contacting Aspose support.

You may use Range,CopyStyle method to achieve your goals. Below provided code snippet demonstrates the usage, whereas detailed article on the subject is available here.

C#

//Load spreadsheet with style to be copied
Workbook book = new Workbook(“input.xlsx”);
//Create a range of data whose style needs to be copied
Range range = book.Worksheets[0].Cells.CreateRange(“A1”, “D3”);

//Create a new Workbook or load another workbook where style has to be pasted
Workbook anotherbook = new Workbook();
//Create a range of similar size on the destination spreadsheet
Range anotherrange = anotherbook.Worksheets[0].Cells.CreateRange(“A1”, “D3”);
//Copy the range style only
anotherrange.CopyStyle(range);
//Save the results
anotherbook.Save(“output.xlsx”, SaveFormat.Xlsx);


Please feel free to write back in case you face any difficulty.