本文介绍了如何在C#中动态重命名excel表名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经创建了一个excel工作簿,其中有很多工作表,如sheet1,sheet2,...等等。如何在C#中动态地重命名这些选项卡名称?
I have created an excel workbook with many sheets like sheet1, sheet2,... etc. How can I rename these tab names dynamically in C#?
推荐答案
您没有加快了如何访问Excel文件。但是,如果您使用的是$ $,则的示例可能对您有用C $ C>的Microsoft.Office.Interop.Excel 。请注意,它打开文件中的第一页,行:(Worksheet)xlBook.Worksheets.get_Item(1)
You didn't spedify how do you access the excel file. However, example from here might be useful for you if you're using Microsoft.Office.Interop.Excel
. Note that it opens first sheet in the file, line: (Worksheet)xlBook.Worksheets.get_Item(1)
using Excel = Microsoft.Office.Interop.Excel;
object oMissing = System.Reflection.Missing.Value;
Excel.ApplicationClass xl=new Excel.ApplicationClass();
Excel.Workbook xlBook;
Excel.Worksheet xlSheet;
string laPath = Server.MapPath(@"\excel\xl_table.xls");
xlBook = (Workbook)xl.Workbooks.Open(laPath,oMissing,
oMissing,oMissing,oMissing ,oMissing,oMissing,oMissing
,oMissing,oMissing,oMissing,oMissing,oMissi ng,oMissing,oMissing);
xlSheet = (Worksheet)xlBook.Worksheets.get_Item(1);
xlSheet.Name = "CIAO";
xlBook.Save();
xl.Application.Workbooks.Close();
这篇关于如何在C#中动态重命名excel表名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!