简体   繁体   中英

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 contains 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";
     }

我正在使用EPPlus来处理所有与Excel相关的代码。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM