Smart Markers & cell styles

I noticed that if I have a smart marker &=DataSet.Coumn(noadd) and I make the text in the cell bold, when the expansion is done, the cells containing the values in column are not bold (except the first one). If I remove ‘noadd’ they are made bold.

Is there way to tell the engine to preserve the style of the cell even when nodadd is used?

Thanks

Hi,

Thanks for your posting and using Aspose.Cells for .NET.

Please use the copystyle attribute of smart markers.

Please see the code below, it is the same code as yours which you posted previously. There are few changes. In cell A3, I am placing the smart marker tag with copystyle attribute.

i.e

worksheet.Cells[“A3”].Value = “&=DataSet.Column1(copystyle)”;

After that I am setting the style of A3 to bold and font color as red.

Style style = worksheet.Cells[“A3”].GetStyle();
style.Font.IsBold = true;
style.Font.Color = Color.Red;
worksheet.Cells[“A3”].SetStyle(style);

Then you can see in the output file that all subsequent values copy the style of cell A3, means all next values will be bold and red.

Here is a complete code, I have attached the output xlsx file generated by the code and the screenshot for your reference.

C#


using System;

using System.Collections.Generic;

using System.Data;

using System.Linq;

using System.Text;

using Aspose.Cells;

using System.Drawing;



namespace TestAspose

{

class Program

{

public static void Main(string[] args)

{

Procedure7();

Console.WriteLine(“Done!”);

Console.ReadKey();

}


private static void Procedure7()

{

WorkbookDesigner designer = new WorkbookDesigner();


DataTable dt = new DataTable();

dt.Columns.Add(“Column1”, typeof(int));

dt.Columns.Add(“Column2”, typeof(string));

dt.Columns.Add(“Column3”, typeof(int));

for (int i = 0; i < 100; i++)

{

dt.Rows.Add(i / 10 + 1, String.Format(“Item {0}”, i), i);

}


designer.SetDataSource(“DataSet”, dt.AsDataView());


Worksheet worksheet = designer.Workbook.Worksheets[0];

worksheet.Cells[“A1”].Formula = “=A3”;

worksheet.Cells[“B1”].Formula = “=$A$3”;

worksheet.Cells[“A3”].Value = “&=DataSet.Column1(copystyle)”;


Style style = worksheet.Cells[“A3”].GetStyle();

style.Font.IsBold = true;

style.Font.Color = Color.Red;

worksheet.Cells[“A3”].SetStyle(style);



designer.Process();


designer.Workbook.CalculateFormula();


Console.WriteLine(“A1={0}”, worksheet.Cells[“A1”].Value);

Console.WriteLine(“B1={0}”, worksheet.Cells[“B1”].Value);


designer.Workbook.Save(“output.xlsx”);


}

}

}


Screenshot:
Hi,

costab:
I noticed that if I have a smart marker &=DataSet.Coumn(noadd) and I make the text in the cell bold, when the expansion is done, the cells containing the values in column are not bold (except the first one). If I remove 'noadd' they are made bold.

Is there way to tell the engine to preserve the style of the cell even when nodadd is used?

Well, that is true and logical. In normal smart markers (the smart markers specified without "noadd" parameter), we will first insert n number of rows (based on the data source) and then start filling data, so the style applied to the smart marker cells would always be preserved/copied in all the rows. When you use "noadd" parameter, it means no rows would be inserted first as the existing rows (cells in the rows) are used with their existing styles. Therefore, when you use "noadd" parameter in the smart markers, the style would be not copied or preserved in all other cells in the column below the smart marker cell (where you specify/update some formatting).

Hope, you understand now.

Also, try and refer to the example that Shakeel Faiz pasted in his post if you want to use "copystyle" parameter.

Thank you.

Using copystyle works very well for me (this is what I was looking for). You can mark this thread as closed.

Thanks

Hi,

Thanks for your feedback.

It’s good to know that your issue is now resolved using copystyle parameter. We will now mark this thread as closed.

If you face any other issue, please feel free to post in this forum, we will be glad to assist you.