diff --git a/docs/csharp/advanced-topics/interop/snippets/OfficeInterop/program.cs b/docs/csharp/advanced-topics/interop/snippets/OfficeInterop/program.cs index e2a062005586c..2845cbdbd4ff2 100644 --- a/docs/csharp/advanced-topics/interop/snippets/OfficeInterop/program.cs +++ b/docs/csharp/advanced-topics/interop/snippets/OfficeInterop/program.cs @@ -61,6 +61,26 @@ static void DisplayInExcel(IEnumerable accounts) // This example uses a single workSheet. The explicit type casting is // removed in a later procedure. Excel._Worksheet workSheet = (Excel.Worksheet)excelApp.ActiveSheet; + + // Establish column headings in cells A1 and B1. + workSheet.Cells[1, "A"] = "ID Number"; + workSheet.Cells[1, "B"] = "Current Balance"; + + var row = 1; + foreach (var acct in accounts) + { + row++; + workSheet.Cells[row, "A"] = acct.ID; + workSheet.Cells[row, "B"] = acct.Balance; + } + + workSheet.Columns[1].AutoFit(); + workSheet.Columns[2].AutoFit(); + + // Put the spreadsheet contents on the clipboard. The Copy method has one + // optional parameter for specifying a destination. Because no argument + // is sent, the destination is the Clipboard. + workSheet.Range["A1:B3"].Copy(); } //