本文整理汇总了C#中Workbook.Descendants方法的典型用法代码示例。如果您正苦于以下问题:C# Workbook.Descendants方法的具体用法?C# Workbook.Descendants怎么用?C# Workbook.Descendants使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Workbook
的用法示例。
在下文中一共展示了Workbook.Descendants方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImportExcelFromFile
/// <summary>
/// Imports all data from the original Excel file
/// </summary>
public void ImportExcelFromFile(string path)
{
_workSheetktExaminedGroup = WorkSheetktExaminedGroup.Instance;
_workSheetUIDesign = WorkSheetktUIDesign.Instance;
_workSheetktUIFieldIncludedType = WorkSheetktUIFieldIncludedType.Instance;
_workSheetktUIGroupOrder = WorkSheetktUIGroupOrder.Instance;
_workSheetktUIOrder = WorkSheetktUIOrder.Instance;
_workSheetktResources = WorkSheetktResources.Instance;
_workSheetktResourceTranslation = WorkSheetktResourceTranslation.Instance;
_workSheetktResourceType = WorkSheetktResourceType.Instance;
_workSheetktUIPageType = WorkSheetUIPageType.Instance;
_workSheetQAGroups = WorkSheetQAGroup.Instance;
_workSheetQAktUIDesign = WorkSheetQAktUIDesign.Instance;
//Check that the file is an excel file
if (CheckFileType(path))
{
if (CheckSheetNames(path))
{
//Open the Excel workbook.
using (SpreadsheetDocument document =
SpreadsheetDocument.Open(path, true))
{
//References to the workbook and Shared String Table.
_workBook = document.WorkbookPart.Workbook;
_workSheets = _workBook.Descendants<Sheet>();
_sharedStrings = document.WorkbookPart.SharedStringTablePart.SharedStringTable;
//Reference to Excel Worksheet with ktExaminedGroup data.
_ktExaminedID = _workSheets.First(s => s.Name == this._workSheetktExaminedGroup.SheetName).Id;
_ktExaminedGroupSheet = (WorksheetPart)document.WorkbookPart.GetPartById(_ktExaminedID);
//Reference to Excel Worksheet with ktUIDesign data.
_ktUiDesignID = _workSheets.First(s => s.Name == this._workSheetUIDesign.SheetName).Id;
_ktUiDesignSheet = (WorksheetPart)document.WorkbookPart.GetPartById(_ktUiDesignID);
//Reference to Excel Worksheet with ktUIFieldIncludedTypeSheet data.
_ktUiFieldID = _workSheets.First(s => s.Name == this._workSheetktUIFieldIncludedType.SheetName).Id;
_ktUiFieldIncludedTypeSheet = (WorksheetPart)document.WorkbookPart.GetPartById(_ktUiFieldID);
//Load ktUIFieldIncludedType data to business object.
this._workSheetktUIFieldIncludedType.LoadUIFieldIncludedType(_ktUiFieldIncludedTypeSheet.Worksheet, _sharedStrings);
//Reference to Excel Worksheet with ktUIFieldIncludedTypeSheet data.
_ktUiGroupOrderID = _workSheets.First(s => s.Name == this._workSheetktUIGroupOrder.SheetName).Id;
_ktUiGroupOrderSheet = (WorksheetPart)document.WorkbookPart.GetPartById(_ktUiGroupOrderID);
//Reference to Excel Worksheet with ktUIFieldIncludedTypeSheet data.
_ktUiOrderID = _workSheets.First(s => s.Name == this._workSheetktUIOrder.SheetName).Id;
_ktUiOrderSheet = (WorksheetPart)document.WorkbookPart.GetPartById(_ktUiOrderID);
//Load ktUIFieldIncludedType data to business object.
//this._workSheetktUIOrder.LoadUIOrder(_ktUiOrderSheet.Worksheet, _sharedStrings);
//Reference to Excel Worksheet with ktResource data.
_ktResourcesID = _workSheets.First(s => s.Name == this._workSheetktResources.SheetName).Id;
_ktResourcesSheet = (WorksheetPart)document.WorkbookPart.GetPartById(_ktResourcesID);
////Load ktResource data to business object.
this._workSheetktResources.LoadktResources(_ktResourcesSheet.Worksheet, _sharedStrings);
////Reference to Excel Worksheet with ktResourceTranslation data.
_ktResourceTranslationID = _workSheets.First(s => s.Name == this._workSheetktResourceTranslation.SheetName).Id;
_ktResourceTranslationSheet = (WorksheetPart)document.WorkbookPart.GetPartById(_ktResourceTranslationID);
////Load ktResouceTranslation data to business object.
this._workSheetktResourceTranslation.LoadktResourceTranslation(_ktResourceTranslationSheet.Worksheet, _sharedStrings);
////Reference to Excel Worksheet with ktResource data.
_ktResourceTypeID = _workSheets.First(s => s.Name == this._workSheetktResourceType.SheetName).Id;
_ktResourceTypeSheet = (WorksheetPart)document.WorkbookPart.GetPartById(_ktResourceTypeID);
////Load ktResource data to business object.
this._workSheetktResourceType.LoadktResourceType(_ktResourceTypeSheet.Worksheet, _sharedStrings);
////Reference to Excel Worksheet with ktUIPageType data.
_ktUiPageTypeID = _workSheets.First(s => s.Name == this._workSheetktUIPageType.SheetName).Id;
_ktUiPageTypeSheet = (WorksheetPart)document.WorkbookPart.GetPartById(_ktUiPageTypeID);
////Load ktResource data to business object.
this._workSheetktUIPageType.LoadUIPageType(_ktUiPageTypeSheet.Worksheet, _sharedStrings);
////Reference to Excel Worksheet with QAGroups data.
_qaGroupsID = _workSheets.First(s => s.Name == this._workSheetQAGroups.SheetName).Id;
_qaGroupsSheet = (WorksheetPart)document.WorkbookPart.GetPartById(_qaGroupsID);
////Load QAGroups data to business object.
this._workSheetQAGroups.LoadQAGroups(_qaGroupsSheet.Worksheet, _sharedStrings);
////Reference to Excel Worksheet with QAGroups data.
_qAktUiDesignID = _workSheets.First(s => s.Name == this._workSheetQAktUIDesign.SheetName).Id;
_qAktUiDesignSheet = (WorksheetPart)document.WorkbookPart.GetPartById(_qAktUiDesignID);
////Load QAGroups data to business object.
this._workSheetQAktUIDesign.LoadQAktUIDesign(_qAktUiDesignSheet.Worksheet, _sharedStrings);
if (this._workSheetktExaminedGroup.LoadExaminedGroup(_ktExaminedGroupSheet.Worksheet, _sharedStrings) &&
//.........这里部分代码省略.........
示例2: CheckSheetNames
/// <summary>
/// Check if the excel file contains the correct sheetnames
/// </summary>
/// <param name="path">Path to the excel file</param>
/// <returns></returns>
public bool CheckSheetNames(string path)
{
using (SpreadsheetDocument document =
SpreadsheetDocument.Open(path, true))
{
//References to the workbook
_workBook = document.WorkbookPart.Workbook;
_workSheets = _workBook.Descendants<Sheet>();
if (_workSheets.Any(x => x.Name == this._workSheetktExaminedGroup.SheetName ||
x.Name == this._workSheetUIDesign.SheetName ||
x.Name == this._workSheetktUIFieldIncludedType.SheetName ||
x.Name == this._workSheetktUIGroupOrder.SheetName ||
x.Name == this._workSheetktUIOrder.SheetName ||
x.Name == this._workSheetktResources.SheetName ||
x.Name == this._workSheetktResourceTranslation.SheetName ||
x.Name == this._workSheetktResourceType.SheetName ||
x.Name == this._workSheetktUIPageType.SheetName ||
x.Name == this._workSheetQAGroups.SheetName ||
x.Name == this._workSheetQAktUIDesign.SheetName))
{
return true;
}
if (_workSheets.Any(x => x.Name == this._workSheetktExaminedGroup.SheetName ||
x.Name == this._workSheetktUIGroupOrder.SheetName ||
x.Name == this._workSheetktUIOrder.SheetName ||
x.Name == this._workSheetktResources.SheetName ||
x.Name == this._workSheetktResourceTranslation.SheetName))
{
return true;
}
SheetNameOk = false;
return false;
}
}