Excel get_range

14,374

Solution 1

I assumed you wanted these in the column headings. If not, change the cell reference in get_Range(). The following will do it:

using Excel = Microsoft.Office.Interop.Excel;

Excel.Range targetRange = targetSheet.get_Range("A1");
targetRange.Value = name;
Excel.Range targetRange = targetSheet.get_Range("E1");
targetRange.Value = value;
Excel.Range targetRange = targetSheet.get_Range("J1");
targetRange.Value = value;

If you don't have any content between A1 and J1 that you want to keep, you can put the values into an object[,] and set the value of A1:J1 in one go, which is a little faster.

Solution 2

The Excel get_range did not work for me. What did work is this:

Range c1 = workSheet.Range[workSheet.Cells[1, 3]];
c1.Value = "name";
Share:
14,374
Tsukasa
Author by

Tsukasa

Updated on June 14, 2022

Comments

  • Tsukasa
    Tsukasa about 2 years

    How can I use Excel get_range to put the following data into a range value.

    I believe I should be able to use get_range to do this, I'm just not sure how.

    Columns

    C1 = name, 
    C5 = value, 
    C10 = value