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, 2022 in Others by Kithuzzz
• 38,010 points
1,745 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, 2022 by narikkadan
• 63,420 points

Related Questions In Others

0 votes
1 answer

A button in excel sheet does not work for the first time

When you press the Display button, the ...READ MORE

answered Mar 30, 2023 in Others by narikkadan
• 63,420 points
232 views
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,440 points
4,846 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, 2022 in Others by narikkadan
• 63,420 points
405 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, 2022 in Others by narikkadan
• 63,420 points
2,309 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, 2022 in Others by gaurav
• 23,260 points
370 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, 2022 in Database by gaurav
• 23,260 points
594 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, 2022 in Database by gaurav
• 23,260 points
1,080 views
0 votes
1 answer

Export DataTable to Excel File

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

answered Jun 9, 2022 in JQuery by gaurav
• 23,260 points
572 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, 2022 in Others by narikkadan
• 63,420 points
1,413 views
0 votes
1 answer

Microsoft.Office.Interop.Excel for Office 2007

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

answered Nov 5, 2022 in Others by narikkadan
• 63,420 points
1,088 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