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

Free Support Forum - aspose.com

Import array of data and apply style

Hi,

I am using ImportArray() method to insert a data set to my Excel workbook.
Newly inserted rows should have a specific style applied - copied from one of existing rows in the worksheet.

Due to the size of my data set I am looking for a most efficient way to perform this task.

Currently I consider to ImportArray() first and than use Workbook.Cells[x,y].ApplyStyle(style, flag) method in two for-loops (rows and columns) to set appropriate formatting for each cells.
Is there some more efficient way to achieve the same goal ?

Hi Sebastian,


Thank you for contacting Aspose support.

If you wish to apply the same styling on a range of cells then most efficient way is to first create an instance of Range using the Cells.CreateRange method. There are several overloads available of said method that would allow you to create a range based on start and end cells. Once you have created a range, you may use the Range.ApplyStyle to set the style as you are currently doing with individual cells.

Please check the following piece of code for better elaboration.

C#

var worksheet = book.Worksheets[0];
//Accessing the cells of first worksheet
var cells = worksheet.Cells;
//Create a range of cells on which you wish to apply style
var range = cells.CreateRange(“A1:B4”);
//Apply style on the range
range.ApplyStyle(style, flag);

If you still face any difficulty, please provide us the sample spreadsheet after importing the array to the worksheet cells. Please also mention which style you would like to apply on what range of cells. We will review your requirements and try to provide you the solution as per need.