Problem to correct the lines

Hi,

What are the equivalent syntax to these
ws.Cell(1, 1).Style.Font.Bold = true;
ws.Cell(1, 1).Style.Fill.BackgroundColor = XLColor.Red;

Open in new window


in VS 2013 C#, as now I cannot choose "Style"

to

worksheet.Cells[1,1], now?

How to resolve this
Error	1	The type or namespace name 'Range' could not be found (are you missing a using directive or an assembly reference?)

Open in new window



to this line?
Range rg = (Excel.Range) worksheet.Cells[1, 1];

Open in new window

LVL 11
HuaMin ChenSystem AnalystAsked:
Who is Participating?
 
Duy PhamFreelance IT ConsultantCommented:
Do you have reference to System.Drawing.dll in your project? Both Color and ColorTranslator are supported in all versions of System.Drawing.dll (up to 4.5), so as long as you have added to that dll in your project, build will be ok.
0
 
Duy PhamFreelance IT ConsultantCommented:
You need to add reference to Microsoft.Office.Interop.Excel.dll, and then a translated code from ExcelPackage to Excel Automation is:
ws.Cells(1, 1).Font.Bold = true;
ws.Cells(1, 1).Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);

Open in new window

0
 
HuaMin ChenSystem AnalystAuthor Commented:
Sorry, I get the error below, to the codes.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Text.RegularExpressions;
using System.Globalization;
using System.Collections;
using System.Diagnostics;
using System.Drawing;
using Microsoft.Office.Interop;
using Excel = Microsoft.Office.Interop.Excel;
...
            worksheet.Cells[1, 1].Font.Bold = true;
            worksheet.Cells[1, 1].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);
            ...

Open in new window

Error	1	The type or namespace name 'ColorTranslator' does not exist in the namespace 'System.Drawing' (are you missing an assembly reference?)
Error	2	The type or namespace name 'Color' does not exist in the namespace 'System.Drawing' (are you missing an assembly reference?)

Open in new window

0
 
HuaMin ChenSystem AnalystAuthor Commented:
Thanks. I'm already using these

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Text.RegularExpressions;
using System.Globalization;
using System.Collections;
using System.Diagnostics;
using System.Drawing;
using Microsoft.Office.Interop;
using Excel = Microsoft.Office.Interop.Excel;
...

Open in new window

how to ensure

System.Drawing

is 4.5?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.