加载工作簿中指定的工作表
Contents
[
Hide
]
默认情况下,Aspose.Cells会将整个电子表格加载到内存中。也可以只加载特定的工作表。这样可以提高性能,减少内存消耗。在处理由许多工作表组成的大型工作簿时,这种方法非常有用。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Define a new Workbook. | |
Workbook workbook; | |
// Load the workbook with the spcified worksheet only. | |
LoadOptions loadOptions = new LoadOptions(LoadFormat.Xlsx); | |
loadOptions.LoadFilter = new CustomLoad(); | |
// Creat the workbook. | |
workbook = new Workbook(dataDir+ "TestData.xlsx", loadOptions); | |
// Perform your desired task. | |
// Save the workbook. | |
workbook.Save(dataDir+ "outputFile.out.xlsx"); |
这里是CustomLoad类的实现。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
class CustomLoad : LoadFilter | |
{ | |
public override void StartSheet(Worksheet sheet) | |
{ | |
if (sheet.Name == "Sheet2") | |
{ | |
// Load everything from worksheet "Sheet2" | |
this.LoadDataFilterOptions = LoadDataFilterOptions.All; | |
} | |
else | |
{ | |
// Load nothing | |
this.LoadDataFilterOptions = LoadDataFilterOptions.Structure; | |
} | |
} | |
} |