Getting Cell Values from Excel API C#

后端 未结 2 1016
小鲜肉
小鲜肉 2020-12-22 04:44

I have a ribbon that i made for Excel along with a cs File to perform as the core of the add-in. When a button is clicked on the CustomRibbon I want to parse the data values

2条回答
  •  执笔经年
    2020-12-22 05:13

    Try using the Value2 field of the cell.

    sheet.Cells[1,1].Value2 = "hello";
    

    Also in this line

    Console.WriteLine(Globals.ThisAddIn.Application.Cells[1, 1]);
    

    The "Cells" field is a property of a worksheet. You can't use it on the Excel application; you need to first create or open a Workbook and then create or use an existing Worksheet.

    EDIT: Forgot that Excel ranges are 1-index and not 0-index.

提交回复
热议问题