Walid Abdelal
Walid Abdelal

Reputation: 61

C# Excel Number Format error

I'm having troubles setting columns format in Excel with Interop. I'm using C#, below is the code:

Excelop.Range rg = (Excelop.Range)wb.Worksheets[1].Cells[1, i];
rg.NumberFormat = "@"; //Exception is raised here

I get the below exception when compiled:

"An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll

Additional information: Unable to set the NumberFormat property of the Range class"

Appreciate your support.

Upvotes: 0

Views: 739

Answers (1)

mjwills
mjwills

Reputation: 23975

My guess is that your worksheet is protected.

You likely need to do something like:

wb.Worksheets[1].Unprotect (Password:"your_password")

These may be of assistance:

https://www.mrexcel.com/forum/excel-questions/449829-run-time-error-1004-unable-set-numberformat-property-range-class.html

"Unable to set the NumberFormat property of the Range class"

Upvotes: 0

Related Questions