Microsoft Office Interop Excel Range does not contain a definition for get Default

0 votes

When I try to export the data grid value to excel it shows an error on the following line.

range = (Range)worksheet.Cells.get_Default(num2 + 10, num);

Microsoft.Office.Interop.Excel.Range' does not contain a definition for 'get_Default' and no extension method 'get_Default' accepting a first argument of type 'Microsoft.Office.Interop.Excel.Range' could be found (are you missing a using directive or an assembly reference?)


 More code

for (int k = inFirstCol; k < dgv.Columns.Count; k++)
{
    range = (Range)worksheet.Cells.get_Default(num2 + 10, num);

    if (dgv[k, j].Style.Font != null)
    {
        if (dgv[k, j].Style.Font.Bold)
        {
            range.Font.Bold = true;
        }
    }
}
Oct 16 in Others by Kithuzzz
• 20,660 points
186 views

1 answer to this question.

0 votes

You are using C# version 4, the synthetic get_Default() method is no longer generated. The WorkSheet interface now has a real indexer, you use it as you do in the rest of your code. Fix:

  range = (Range)worksheet.Cells[num2 + 10, num];

I'll give a brief explanation of get_Default( ) COM Automation supports indexed properties and provides a more open conception of properties. Alternatively, properties that accept additional arguments. It also enables designating a property as an interface's default property. This has historically been a relatively severe requirement in the C# language. Although it does support a default property,, its name is fixed. the class's indexer. When the program is constructed, it is given the new name Item. And just one argument is allowed. With COM interop, where the default property might have any name and any number of arguments, this did not work out so well. This issue arises from the Range interface's Value default attribute, which accepts two arguments. They are optional as well, which was another feature that C# did not support. 

C# version 4 greatly improved this, it now supports indexed properties as well. But only in the specific case of COM interop. If you look at the Range interface with Object Explorer you now see:

  dynamic this[[object RowIndex = System.Type.Missing], 
               [object ColumnIndex = System.Type.Missing]] 
  { set; get; }
answered Oct 16 by narikkadan
• 37,660 points

Related Questions In Others

0 votes
1 answer

Flutter Error: MediaQuery.of() called with a context that does not contain a MediaQuery.

Hi@akhtar, You need a MaterialApp or a WidgetsApp around your widget. They ...READ MORE

answered Aug 27, 2020 in Others by MD
• 95,380 points
4,064 views
0 votes
1 answer

JavaScript API does not work for Excel 2013?

Each method in the Office.js APIs is ...READ MORE

answered Sep 26 in Others by narikkadan
• 37,660 points
54 views
0 votes
1 answer

How to reference Microsoft.Office.Interop.Excel dll?

Use NuGet (VS 2013+): The NuGet package manager ...READ MORE

answered Oct 9 in Others by narikkadan
• 37,660 points
167 views
0 votes
1 answer

How to add Conditional Formatting in Excel for a Range of Values

Three distinct rules are required, one for ...READ MORE

answered Oct 24 in Others by narikkadan
• 37,660 points
45 views
0 votes
1 answer

Generate a flat list of all excel cell formulas

Hello, you'll have to follow certain steps ...READ MORE

answered Feb 18 in Others by gaurav
• 22,040 points
80 views
0 votes
1 answer

Convert a number to a letter in C# for use in Microsoft Excel [duplicate]

If you are familiar with using formulas ...READ MORE

answered Feb 23 in Database by gaurav
• 22,040 points
147 views
0 votes
1 answer

Deleting duplicate rows in Excel using Epplus

You need to re-think this… the while ...READ MORE

answered Feb 23 in Database by gaurav
• 22,040 points
302 views
0 votes
1 answer

Export DataTable to Excel File

Add Interop References. First we need to ...READ MORE

answered Jun 9 in JQuery by gaurav
• 22,040 points
123 views
0 votes
1 answer

c#, Microsoft Interop Excel , change font style for s selected range

Change your code to this: worksheet.get_Range("B3", "B4").Cells.Font.Name = ...READ MORE

answered Oct 31 in Others by narikkadan
• 37,660 points
63 views
0 votes
1 answer

Microsoft.Office.Interop.Excel for Office 2007

Each client must install the  2007 Microsoft ...READ MORE

answered Nov 5 in Others by narikkadan
• 37,660 points
73 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP