Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Cell.GetStyle and Cell.SetStyle. This article examines the Cell.GetStyle/SetStyle approach to help you decide which technique best suits you.
There are two ways to format a cell, illustrated below.
With the following piece of code, a Style object is created for each cell when formatting it. If a large number of cells are being formatted, a great amount of memory is consumed because the Style object is sizable. These Style objects are not freed until the Workbook.Save method is called.
C++
cell.GetStyle().GetFont().SetIsBold(true);
The first approach is easy and straightforward, so why did we add the second approach?
We added the second approach to optimize memory usage. After using the Cell.GetStyle method to retrieve a Style object, modify it, and then use the Cell.SetStyle method to set it back to the cell, this Style object will not be retained, and the C++ runtime will collect it when it is no longer referenced.
When calling the Cell.SetStyle method, the Style object isn’t saved for each cell. Instead, we compare this Style object to an internal Style object pool to see if it can be reused. Only Style objects that differ from the existing ones are kept for each Workbook object. This means that there are only several hundred Style objects for each Excel file instead of thousands. For each cell, only an index to the Style object pool is preserved.
C++
auto style = cell.GetStyle();
style.GetFont().SetIsBold(true);
cell.SetStyle(style);
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.