我正在尝试使用Open XML API以编程方式在Excel中对(shift select)工作表进行分组。我知道如何以Interop方式执行此操作:
String[] sheetsToBeSelected = {"Sheet1","Sheet2","Sheet3"};
excel.Workbook workbook = ExcelApp.ActiveWorkbook;
excel.Sheets worksheets = workbook.Worksheets;
((excel.Sheets)worksheets.get_Item(sheetsToBeSelected)).Select();
很难将其翻译成Open XML API,但没有运气。请帮忙。
感谢。
答案 0 :(得分:1)
尝试设置SheetView的TabSelected属性。这是示例代码
foreach(Sheet sht in myWorkBook.WorkBook.Descendants<Sheet>())
{
WorkSheetPart wrkShtPart = (WorkSheetPart)myWorkBook.GetPartById(sht.Id);
SheetViews shtViews = wrkShtPart.WorkSheet.GetFirstChild<SheetViews>();
SheetView shtView = shtViews.GetFirstChild<SheetView>();
shtView.TabSelected = null;
}