Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,

I need to highlight a cell using a script task with SSIS. I can get the cell value which means that my script works :

OleDbDataAdapter objAdapterDataCell = new
       OleDbDataAdapter(strSQLDataCell, cn);
       DataSet dsDataCell = new DataSet();
       objAdapterDataCell.Fill(dsDataCell, Data_Sheet);
       System.Data.DataTable dtDataCell = dsDataCell.Tables[Data_Sheet];
       object CellToHigh = dsDataCell.Tables[Data_Sheet].Rows[RowIndex]
       [ColumnIndex];


What I have tried:

When adding this nothing happening :

<pre>  dsDataCell.Tables[Data_Sheet].Rows[RowIndex][ColumnIndex] = 
        Color.Red;
        excelBook.Save();
        excelBook.Close();
        MessageBox.Show(CellToHigh.ToString());
        xlApp.Quit();
        Marshal.ReleaseComObject(xlApp);
        Dts.TaskResult = (int)ScriptResults.Success;


Thank you for your Help.
Posted
Updated 5-Feb-19 22:21pm
Comments
[no name] 31-Jan-19 14:06pm    
The "Color.Red" is simply going to come out as a number (somewhere).

Excel is not "aware" of .NET "colors".
Member 12887760 1-Feb-19 9:54am    
Thanks for your answer Gerry and how can I solve that please ?
Member 12887760 1-Feb-19 10:00am    
I actually need to change th color of the cell based on its RowIndex and ColumnIndex

1 solution

What you are trying to attempt in this line:
dsDataCell.Tables[Data_Sheet].Rows[RowIndex][ColumnIndex] = Color.Red;

is to change a value in a cell of "Data_Sheet" DataTable, which is impossible!
Note: Color.Red returns a system-defined color that has an ARGB value of #FFFF0000

You should rather change color of Excel cell. How?
How to: Programmatically apply color to Excel ranges - Visual Studio | Microsoft Docs[^]

Excel.Range rng2 = excelSheet.get_Range("A1");
rng2.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);
 
Share this answer
 
v2
Comments
Member 12887760 7-Feb-19 8:49am    
@Maciej Los, Thank you for your answer. I actually should use Microsoft.Office.Interop.Excel combined with your answer to use Range instead of Dataset and it solves my issue.
Maciej Los 7-Feb-19 8:57am    
You're very welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900