When use the SetDataSource , and use xx.cells[]. SetStyle

Hi ,I have a problem ,when I use for to set style , not useful

for (int i = 0; i < 5; i++)
{
testList.Add(new SampleData
{
olsStyle.ForegroundColor = Color.FromArgb(yellow);
wooksheet.Cells[row, i].SetStyle(olsStyle);
});
}}

wbd.SetDataSource(“Test”, testList);

the style not useful , they all under the row
can you tell if somewhere wrong

QQ截图20180531203634.png (2.8 KB)

Thanks very much.

@weiwei_si,

Thanks for the screenshot and code segment.

Could you provide us complete sample code (runnable) or preferably a simple console demo application (you may zip the project prior attaching here) and provide us here to show the issue. Also provide your template Excel file (if any) and output Excel file. This will help us really to evaluate your issue precisely to consequently figure it out soon.

Sorry for so confused .this is the code ,and screenshot

class Program
{
static void Main(string[] args)
{
WorkbookDesigner wbd = new WorkbookDesigner();

		var templatePath = @"Test_Template.xlsx";
		var testPath = $@"Test_Template_{DateTime.Now.ToString("ddMMMyy_hhmmss")}.xlsx";

		var license = new Aspose.Cells.License();
		license.SetLicense("Aspose.Cells.net.lic");

		var testList = new List<SampleData>();

		Workbook workbook = new Workbook(templatePath);
		wbd.Workbook = workbook;
		Style olsStyle = workbook.Worksheets[0].Cells[0,0].GetStyle(true);
		olsStyle.BackgroundColor = Color.Red;
		for ( int i = 0; i < 5; i++ ) {
			testList.Add(new SampleData {
				Col1 = i.ToString(),
				Col2 = i.ToString(),
				Col3 = i.ToString()
			});
		}
		wbd.SetDataSource("testList", testList);
		for ( int i = 1; i < 6; i++ ) {
			workbook.Worksheets[0].Cells["B" + i].SetStyle(olsStyle);
			workbook.Worksheets[0].Cells["C" + i].SetStyle(olsStyle);
			workbook.Worksheets[0].Cells["D" + i].SetStyle(olsStyle);
		}

		wbd.Process();
		wbd.Workbook.Save(testPath);
	}
	public   class SampleData
	{
		public string Col1 { get; set; }
		public string Col2 { get; set; }
		public string Col3 { get; set; }
	}
}<a class="attachment" href="/uploads/default/15314">3.png</a> (9.0 KB)

7.png (5.1 KB)

3.png (9.0 KB)
7.png (5.1 KB)

@weiwei_si

Thanks for using Aspose APIs.

Please use

olsStyle.SetPatternColor(BackgroundType.Solid, Color.Red, Color.Red); 

to set background color.

By the way, if you set the excepted style in the template file, then we will automatically copy style when processing smart markers.