reading huge data from excel using Microsoft.Office.Interop.Excel in C#

1

I am reading from .xlsx file(in C#) having huge data (max length of few columns is 415000 using Microsoft.Office.Interop.Excel, the file has 12 columns each with different length. I want to find the length of specific columns say for example 3,4,5

I was trying to do something like below(as I dont see any direct function to calculate actual length of column) but gives Not enough storage is available to complete this operation. (Exception from HRESULT: 0x8007000E (E_OUTOFMEMORY)) at line 1

int rows = excelWorksheet.UsedRange.Rows.Count;
Excel.Range excelRange = excelWorksheet.UsedRange;
object[,] valueArr = (object[,])excelRange.get_Value(Excel.XlRangeValueDataType.xlRangeValueDefault);.......1

int[] columnSize = new int[valueArr.Length / rows+1];

Then looping over the columns to find the length of each column by looping over till its row has data

Can someone help on this? Is there any direct method to find length of column...

c#
office-interop
asked on Stack Overflow Jul 18, 2011 by PAR • edited Jul 19, 2011 by PAR

1 Answer

0

Consider using the Open XML SDK from Microsoft, which allows you to load an XLSX file as an XML document. Using Linq-to-XML might be a more efficient way to manipulate your large Excel files than to use Excel and doing interop.

You can find more information about Open XML on MSDN.

answered on Stack Overflow Jul 18, 2011 by Philipp Schmid

User contributions licensed under CC BY-SA 3.0