Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio 使用C在Excel工作表中插入数据#_Visual Studio_C# 4.0_Excel 2010 - Fatal编程技术网

Visual studio 使用C在Excel工作表中插入数据#

Visual studio 使用C在Excel工作表中插入数据#,visual-studio,c#-4.0,excel-2010,Visual Studio,C# 4.0,Excel 2010,我正在尝试使用C#在Excel工作表中插入数据,代码和运行中的一切都正常,但数据没有插入Excel工作表中 提示:我使用与成功插入数据相同的代码在另一个Excel工作表中插入了另一个数据。请尝试以下代码 var excelApp = new Excel.Application(); Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(@"Excel.xlsx"); Excel._Worksheet excelWor

我正在尝试使用C#在Excel工作表中插入数据,代码和运行中的一切都正常,但数据没有插入Excel工作表中

提示:我使用与成功插入数据相同的代码在另一个Excel工作表中插入了另一个数据。

请尝试以下代码

    var excelApp = new Excel.Application();
    Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(@"Excel.xlsx");
    Excel._Worksheet excelWorkSheet = (Excel._Worksheet)excelWorkbook.Sheets[1];
    excelWorkSheet = (Excel._Worksheet)excelApp.ActiveSheet;
    Excel.Range excelRange = excelWorkSheet.UsedRange;
    int rowCount = excelRange.Rows.Count;
    excelApp.Visible = true;
    excelWorkSheet.Cells[1, "A"] = "Insert";
    excelWorkSheet.Cells[1, "B"] = "your";
    excelWorkSheet.Cells[1, "C"] = "text";
    excelWorkSheet.Cells[1, "D"] = "here";
    excelWorkbook.Close(true, "output.xlsx");
    excelApp.Quit();