Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.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
C# 如何使用c在工作簿中打开相应的excel工作表#_C#_Excel - Fatal编程技术网

C# 如何使用c在工作簿中打开相应的excel工作表#

C# 如何使用c在工作簿中打开相应的excel工作表#,c#,excel,C#,Excel,我的代码打开excel的第一页。我的目标是打开组合框中选定的工作表。是否有人可以帮助我找到解决方案: 我的代码: 按图纸名称 Microsoft.Office.Interop.Excel.Worksheet wsh = (Worksheet)excelsheet["SheetName"]; 按索引(从1开始-第一页) 只需在组合框中使用其中一个值。 如果要用可用的工作表填充组合框,可以浏览工作表 foreach (Worksheet Sh in excelsheet) { Combob

我的代码打开excel的第一页。我的目标是打开组合框中选定的工作表。是否有人可以帮助我找到解决方案:

我的代码:

按图纸名称

Microsoft.Office.Interop.Excel.Worksheet wsh = (Worksheet)excelsheet["SheetName"];
按索引(从1开始-第一页)

只需在组合框中使用其中一个值。 如果要用可用的工作表填充组合框,可以浏览
工作表

foreach (Worksheet Sh in excelsheet)
{
    Combobox.Items.Add(Sh.Name); 
}
然后,组合框的选定值将已经是一个工作表名称,您可以通过以下方式获得:

Microsoft.Office.Interop.Excel.Worksheet wsh = (Worksheet)excelsheet[Combobox.SelectedValue]; //I'm not sure if combobox value is got like this, but the excel part is ok.
foreach (Worksheet Sh in excelsheet)
{
    Combobox.Items.Add(Sh.Name); 
}
Microsoft.Office.Interop.Excel.Worksheet wsh = (Worksheet)excelsheet[Combobox.SelectedValue]; //I'm not sure if combobox value is got like this, but the excel part is ok.