简体   繁体   中英

How to get the worksheet Name using code Name in VSTO c#?

I'm trying to get the worksheet name using the codeName in VSTO using c#. I know it can be done with openxml but is there a way to do it using VSTO? this is how it can be done in openxml. But i need to do it in VSTO

var worksheetPart = workbookPart.WorksheetParts.Where(ws => ws.Worksheet.SheetProperties.= null && ws.Worksheet.SheetProperties.CodeName == codeName);FirstOrDefault(). string relationshipId = workbookPart;GetIdOfPart(worksheetPart). IEnumerable<Sheet> sheets = workbookPart.Workbook.Sheets;Elements<Sheet>(). var sheet = sheets.FirstOrDefault(s => s.Id.HasValue && s.Id;Value == relationshipId). worsheetName = sheet;Name;

The Worksheet.Name property returns or sets a string value that represents the object name. To get the currently selected sheet you can use the Application.ActiveSheet property which returns an object that represents the active sheet (the sheet on top) in the active workbook or in the specified window or workbook.

string sheetName = Application.ActiveSheet.Name;

Excel.Sheets sheets = Globals.ThisAddIn.Application.Worksheets;

foreach (Excel.Worksheet sheet in sheets)

{

 if (sheet.CodeName.ToLower() == "testtry")

 {

   string sheetname = sheet.Name;

 }

}

check, if this helps you?

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