Understanding the Dynamic Keyword in C# 4: Listing 2

Scripting Excel with C#

// Add this line to the beginning of the file:
// using Excel = Microsoft.Office.Interop.Excel;

var excelApp = new Excel.Application();

excelApp.Workbooks.Add();
// excelApp.Workbooks.Add(Type.Missing);

excelApp.Visible = true;

Excel.Range targetRange = excelApp.Range["A1"];
// Excel.Range targetRange = excelApp.get_Range("A1", Type.Missing);

targetRange.Value = "Name";
// targetRange.set_Value(Type.Missing, "Name");

targetRange.Columns[1].AutoFit();
// ((Excel.Range)targetRange.Columns[1, Type.Missing]).AutoFit();

About the Author

Alexandra Rusina is a program manager on the Silverlight team. Prior to that she worked as a programming writer on the Visual Studio Languages team during the Visual Studio 2010 release. She also regularly blogged on the C# Frequently Asked Question blog.

comments powered by Disqus

Featured

  • What's New in TypeScript 5.3

    Microsoft advanced TypeScript to version 5.3 with a bevy of changes affecting everything from import attributes to interactive inlay hints for types, along with multiple optimizations.

  • Finally Go Eyes On with Upcoming Visual Studio 2022 UI Refresh

    Six months ago, Microsoft teased Visual Studio 2022 developers by announcing an upcoming UI refresh, which they can now finally get their eyes on in the new v17.9 preview 1.

  • DBSCAN Data Clustering from Scratch Using C#

    Compared to other clustering techniques, DBSCAN does not require you to explicitly specify how many data clusters to use, explains Dr. James McCaffrey of Microsoft Research in this full-code, step-by-step machine language tutorial.

  • GitHub Copilot Leads Productivity Gains in New Visual Studio 2022 17.8

    In announcing Visual Studio 2022 17.8 today, Microsoft emphasized community-driven productivity gains among the new features and functionality.

  • Microsoft Ships .NET 8

    In announcing .NET 8 today, Microsoft emphasized the cloud, performance, full-stack Blazor, AI and .NET MAUI as major highlights of the latest edition of the company's free, cross-platform, open source developer platform.

Subscribe on YouTube

Upcoming Events