Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.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# 如何使用NetOffice重命名Excel工作表?_C#_Excel_Excel Interop - Fatal编程技术网

C# 如何使用NetOffice重命名Excel工作表?

C# 如何使用NetOffice重命名Excel工作表?,c#,excel,excel-interop,C#,Excel,Excel Interop,我试图使用NetOffice在我的c#应用程序中创建excel工作簿,但在尝试重命名工作表和使用单元格范围排序时遇到了一个障碍。NetOffice无法识别以下代码行,我正在努力找到一种方法,使用NetOffice重命名工作表并对单元格区域进行排序 workbook.Worksheets[sheetCountPlusONe].name = "Event " + sheetCountPlusONe.ToString() + " Results"; 这也不起作用。这是我声明和排序一系列单元格的地方:

我试图使用NetOffice在我的c#应用程序中创建excel工作簿,但在尝试重命名工作表和使用单元格范围排序时遇到了一个障碍。NetOffice无法识别以下代码行,我正在努力找到一种方法,使用NetOffice重命名工作表并对单元格区域进行排序

workbook.Worksheets[sheetCountPlusONe].name = "Event " + sheetCountPlusONe.ToString() + " Results";
这也不起作用。这是我声明和排序一系列单元格的地方:

Excel.Range valueRange;
Excel.Range placeRange;
placeRange = worksheet.get_Range("A14", "A" + (14 + (registrationForm.numberofCompetitors - 1)).ToString());
valueRange = worksheet.get_Range("A14", "K"+(14+(registrationForm.numberofCompetitors-1)).ToString());
valueRange.Sort(valueRange.Columns[3, Type.Missing], Excel.XlSortOrder.xlDescending, Type.Missing, Type.Missing, Excel.XlSortOrder.xlAscending, Type.Missing, Excel.XlSortOrder.xlAscending, Excel.XlYesNoGuess.xlGuess, Type.Missing, Type.Missing, Excel.XlSortOrientation.xlSortColumns, Excel.XlSortMethod.xlPinYin, Excel.XlSortDataOption.xlSortNormal, Excel.XlSortDataOption.xlSortNormal, Excel.XlSortDataOption.xlSortNormal);
placeRange.Sort(placeRange.Columns[1, Type.Missing], Excel.XlSortOrder.xlAscending, Type.Missing, Type.Missing, Excel.XlSortOrder.xlAscending, Type.Missing, Excel.XlSortOrder.xlAscending, Excel.XlYesNoGuess.xlGuess, Type.Missing, Type.Missing, Excel.XlSortOrientation.xlSortColumns, Excel.XlSortMethod.xlPinYin, Excel.XlSortDataOption.xlSortNormal, Excel.XlSortDataOption.xlSortNormal, Excel.XlSortDataOption.xlSortNormal); 

我想知道你的问题。以下代码可以正常工作:

Excel.Application excelApplication = new Excel.Application();
Excel.Workbook workBook = excelApplication.Workbooks.Add();
Excel.Worksheet workSheet = workBook.Worksheets[1] as Excel.Worksheet;
workSheet.Name = "AnyNameYouWant";
“sheetCountPlusOne”是一个大于您收藏规模的整数吗?您必须先添加图纸,然后才能重命名它


对于排序,如果可能的话,我建议使用.NET 4的命名参数,并避免令人头痛的.Missing类型列表。

您尝试过.Name吗?将它显示为资本化的财产。是的,我做了,它有点起作用。我希望有更多关于如何使用NetOffice online的文档。这个网站只是很有帮助。我在实施上有困难。