C# Check for a WorkSheet name of an excel file and rename it
I need help in writing a C# code which basically should take excel file as input and check if the excel file con开发者_如何学JAVAtains a specific worksheet or tab and if yes rename that tab with another name. The program should support .net 3.5 and excel 2007. Please provide me some examples. Thanks in advance.
Application excel = new Application();
Workbook wb = excel.Workbooks.Open(path, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
string lookFor="TabName1";
foreach (Microsoft.Off.Interop.Excel.Worksheet w in wb.Worksheets)
{
if (w.Name == lookFor)
//match exists rename
w.Name = lookFor + "_renamed";
}
I'm using EPPlus for all Excel-related code.
Full length code From one of the stack over posts
精彩评论