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

Free Support Forum - aspose.com

Applying styles to multiple cells without using GridDesktop

Hello,

I am evaluating Aspose.Cells for .NET and prefer to just use the Aspose.Cells.dll, since the test application should be able to run within a Windows service.

I found the documentation on applying a style to multiple cells:
Formatting a Range of Cells

However this needs the Aspose.Cells.GridDesktop.dll.

Questions:

  • is the Aspose.Cells.GridDesktop.dll recommended for use inside a service, also in terms of multithreading and overhead.
  • is there a way to apply styles to multiple cells without using GridDesktop, other than looping over each individual cell?

Thanks for your input.

Hi Bernard,


Thank you for considering Aspose APIs.

Please note, Aspose.Cells.GridDesktop is a visual component to be used in .NET Forms applications in order to simulate a subset of features provided by Excel application. If you intend to use the Aspose.Cells for .NET APIs as a back-end service then you should be using the Aspose.Cells.dll in your application.

Regarding your question about applying styles on a range of cells, please review the following piece of code that demonstrates the concept in terms of Aspose.Cells for .NET API.

C#

//Create an instance of Workbook
//Optionally load an existing spreadsheet
var book = new Workbook();
//Retrieve the first Worksheet
var sheet = book.Worksheets[0];
//Retrieve the cells of first worksheet
var cells = sheet.Cells;
//Create a range of cells from A1:A10
var range = cells.CreateRange(“A1:A10”);
//Create an instance of Style & add it to styles pool
var style = book.CreateStyle();
//Set attributes for the Style object
style.Font.Name = “Arial”;
style.Font.Size = 20;
style.Font.Color = Color.White;
style.ForegroundColor = Color.Red;
style.Pattern = BackgroundType.Solid;
//Setting the line style of the top border
style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thick;
//Setting the color of the top border
style.Borders[BorderType.TopBorder].Color = Color.Black;
//Setting the line style of the bottom border
style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thick;
//Setting the color of the bottom border
style.Borders[BorderType.BottomBorder].Color = Color.Black;
//Setting the line style of the left border
style.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thick;
//Setting the color of the left border
style.Borders[BorderType.LeftBorder].Color = Color.Black;
//Setting the line style of the right border
style.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thick;
//Setting the color of the right border
style.Borders[BorderType.RightBorder].Color = Color.Black;
//Apply style onto the previously defined range
//StyleFlag decides which aspects of the new style would take effect
range.ApplyStyle(style, new StyleFlag() { All = true });
//Save the result onto disk
book.Save(dir + “output.xlsx”);

Please also note that Aspose.Cells is a pure .NET component created in managed C#, therefore concurrency and multi-threading is not a problem by any means. As long you don't have shared data source and every time a user access a new Workbook or Excel file in different thread, there will be no problem at all. However, if you have a shared data/resource or the same workbook is being accessed then you have to do the synchronization on your own.

Thanks for your quick feedback!

Hi Bernard,

You are most welcome. Please feel free to contact us back in case you need our further assistance with Aspose APIs.