【发布时间】:2015-08-29 11:34:36
【问题描述】:
我在 Excel 文件中制作了一些表格。我用这段代码同时做了很多:
newSheet2 = (Microsoft.Office.Interop.Excel._Worksheet)newWorkbook_First.Sheets.Add(Type.Missing,Type.Missing,5,Type.Missing);
...但我不知道如何单独命名它们。我认为它必须这样做:
newSheet2[2].name = "hello"
但这给出了一个错误。我该怎么做?
private static Microsoft.Office.Interop.Excel.ApplicationClass appExcel;
private static Workbook newWorkbook_First = null;
private static _Worksheet newSheet2 = null;
public void excel_create(String path)
{
try
{
appExcel = new Microsoft.Office.Interop.Excel.ApplicationClass();
appExcel.Visible = true;
newWorkbook_First = appExcel.Workbooks.Add(1);
newSheet2 = (Microsoft.Office.Interop.Excel._Worksheet)newWorkbook_First.Sheets.Add(Type.Missing,Type.Missing,5,Type.Missing);
//How to name the sheets now?
}
catch (Exception e)
{
Console.Write("Error");
}
finally
{
}
}
【问题讨论】:
标签: c# excel rename excel-interop