Large excel files

Hi, I was wondering if it was possible to load only part of a worksheet? We have an issue in production with some customers who have very large excel files causing issues.

Hi,

Yes, you can partially load a workbook with your selected worksheet and leave others.

Please download and use the latest version:
Aspose.Cells
for .NET v7.3.2.3


Please try the following code with the sample xlsx file attached by me.

a) - If you just want to load data of one worksheet, please try the following code:

C#


LoadOptions loadOptions = new LoadOptions(LoadFormat.Xlsx);
LoadDataOption dataOption = new LoadDataOption();
dataOption.SheetIndexes = new int[] { 0 };
dataOption.ImportFormula = true;
loadOptions.LoadDataOnly = true;

//Specify the LoadDataOption
loadOptions.LoadDataOptions = dataOption;

//Create a Workbook object and opening the file from its path
Workbook wb = new Workbook(Constants.sourcePath + “Source.xlsx”, loadOptions);


Worksheet sheet1 = wb.Worksheets[0];
Worksheet sheet2 = wb.Worksheets[1];
Worksheet sheet3 = wb.Worksheets[2];


Cell cellA1OfSheet1 = sheet1.Cells[“A1”];
Cell cellA1OfSheet2 = sheet2.Cells[“A1”];
Cell cellA1OfSheet3 = sheet3.Cells[“A1”];

Debug.Assert(cellA1OfSheet2.Type == CellValueType.IsNull, “This message should not appear”);

Debug.Assert(cellA1OfSheet3.Type == CellValueType.IsNull, “This message should not appear”);

VB.NET
Dim filePath As String = "F:\Shak-Data-RW\Downloads\source.xlsx"


Dim loadOptions As LoadOptions = New LoadOptions(LoadFormat.Xlsx)

Dim dataOption As LoadDataOption = New LoadDataOption()

dataOption.SheetIndexes = New Integer() {0}

dataOption.ImportFormula = True

loadOptions.LoadDataOnly = True


'Specify the LoadDataOption

loadOptions.LoadDataOptions = dataOption


'Create a Workbook object and opening the file from its path

Dim wb As Workbook = New Workbook(filePath, loadOptions)


Dim sheet1 As Worksheet = wb.Worksheets(0)

Dim sheet2 As Worksheet = wb.Worksheets(1)

Dim sheet3 As Worksheet = wb.Worksheets(2)


Dim cellA1OfSheet1 As Cell = sheet1.Cells(“A1”)

Dim cellA1OfSheet2 As Cell = sheet2.Cells(“A1”)

Dim cellA1OfSheet3 As Cell = sheet3.Cells(“A1”)


Debug.Assert(cellA1OfSheet2.Type = CellValueType.IsNull, “This message should not appear”)

Debug.Assert(cellA1OfSheet3.Type = CellValueType.IsNull, “This message should not appear”)


b) - If you just want to get the all sheets’ name, please use the following code:

C#
dataOption.SheetIndexes = new int[] { };

Thanks for the prompt reply. This might help us but is it possible to only load a partial worksheet or do you still need to load the entire sheet?

Hi,


I am afraid, there is no way to load a worksheet partially, either you have to load the entire sheet or not.

Thanks,

That's what I figured but thought I'd check. Thanks again for the prompt replies!

-Eric

Hi,

Thanks for your posting and using Aspose.Cells.

If you get any other question relating to Aspose.Cells, please feel free to post, we will be glad to help you asap.

Please also download and try the latest offline demos. These will help you to be quickly familiar of Aspose.Cells.

These demos can work with Visual Studio 2005, 2008 or 2010. Please read the readme.txt file before running the demos.