Problem Changing bacground color

  1. I have a problem with changing Background,
    I’ve tried to follow an example from another thread, but it did not solve the problem. The background remains unchanged(i.e. default). all the data is being importec correctly
    btw, where do numbers 54 & 55 in your example come from?

    2) Also, could you please let me know if you have any recommendation on improving the workflow
    (the idea is that I want to combine smart markers with using ImportDataTable/ImportColumn)
    I can’t use smart markers to import columns, because the columns&headers may change depending on the search criteria (or is there still a way to use smart markers if the columns are dynamically generated?)
    when I create excel file for download, I have: DataGrid which has column headers and bound to the datatable which has one page of data, and a different data table that has the same structure, but all the data(this it the table that should be downloaded).

    here is the code I use:

    ExcelDesigner designer = new ExcelDesigner();

    …// read template file in to stream
    designer.Open(memoryStream);
    // file has one worksheet with some variables i.e. &=$test

    designer.SetDataSource(“test”,“value”); // this works fine
    designer.process();


    designer.Excel.worksheets.Add();
    int sheetNumber=designer.Excel.Worksheets.Count-1;

    designer.Excel.ChangePalette(Color.DarkBlue,55);

    //
    for( each column)
    {
    // import column

    designer.Excel.Worksheets[sheetNumber].Cells[row,column].Style.BackgroundColor=Color.DarkBlue; // change background for header

    }

    designer.SaveToStream(…)

  1. Please change your code to

designer.Excel.Worksheets[sheetNumber].Cells[row,column].Style.ForegroundColor=Color.DarkBlue;

There are 56 different colors in a standard Excel palette. You can see it when you format a cell. To add an extra color to the file, you have to change the palette at first. About the 56 colors of the palette, please check http://www.aspose.com/Products/Aspose.Excel/Api/Aspose.Excel.Excel.ChangePalette.html

  1. You can use Cell.PutValue to put smart markers at run time, and then set data source, finally call process method. Then you can dynamically process the data with smart markers.

@IgorS,
Aspose.Excel is discontinued and no more under development now. It is replaced by Aspose.Cells that is much advanced and better in performance as compared to its predecessor. It contains many advanced features to format cells by adding borders, adding custom colors to a palette, and setting background and foreground colors. The following example demonstrates setting the background color.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
    System.IO.Directory.CreateDirectory(dataDir);

// Instantiating a Workbook object
Workbook workbook = new Workbook();

// Adding a new worksheet to the Workbook object
int i = workbook.Worksheets.Add();

// Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[i];

// Define a Style and get the A1 cell style
Style style = worksheet.Cells["A1"].GetStyle();

// Setting the foreground color to yellow
style.ForegroundColor = Color.Yellow;

// Setting the background pattern to vertical stripe
style.Pattern = BackgroundType.VerticalStripe;

// Apply the style to A1 cell
worksheet.Cells["A1"].SetStyle(style);

// Get the A2 cell style
style = worksheet.Cells["A2"].GetStyle();

// Setting the foreground color to blue
style.ForegroundColor = Color.Blue;

// Setting the background color to yellow
style.BackgroundColor = Color.Yellow;

// Setting the background pattern to vertical stripe
style.Pattern = BackgroundType.VerticalStripe;

// Apply the style to A2 cell
worksheet.Cells["A2"].SetStyle(style);

// Saving the Excel file
workbook.Save(dataDir + "book1.out.xls", SaveFormat.Excel97To2003);

Here is a document that can be referred to for more information on cells formatting:
Cells Formatting

You can download the latest trial version here:
Aspose.Cells for .NET (Latest Version)

You can test all the features of this product by downloading a runnable solution here.