ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Add Excel Range to Lists without looping in C#<p>Please share complete code</p>https://www.aspforums.net:443/Threads/202981/Add-Excel-Range-to-Lists-without-looping-in-C/https://www.aspforums.net:443/Threads/202981/Add-Excel-Range-to-Lists-without-looping-in-C/Tue, 12 Jul 2016 05:52:39 GMTAdd Excel Range to Lists without looping in C#<p>&nbsp;</p> <pre class="brush: csharp">Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbook xlWorkBookDB; Microsoft.Office.Interop.Excel.Worksheet xlWorkSheetDB; Microsoft.Office.Interop.Excel.Range xlRangeDB; int lRow = 0; //Open Excel Workbook to read data xlWorkBookDB = xlApp.Workbooks.Open(TestWorkbook1, false, true, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); //Name Excel Sheet from where data needs to be taken Worksheet xlWorkSheetDB = xlWorkBookDB.Worksheets[&#34;DB&#34;]; // Check if there is any data available in the worksheet int dataCount = (int)xlApp.WorksheetFunction.CountA(xlWorkSheetDB.Cells); if (dataCount &gt; 0) { lRow = xlWorkSheetDB.Cells.Find(&#34;*&#34;, xlWorkSheetDB.get_Range(&#34;A1&#34;), Type.Missing, Type.Missing, XlSearchOrder.xlByRows, XlSearchDirection.xlPrevious).Row; } //Name a range to get data from xlRangeDB = xlWorkSheetDB.get_Range(&#34;A2&#34;, &#34;BA&#34; + lRow.ToString()); //read above range into an array object[,] valueArray = xlRangeDB.Value2; //Try to add that array data into List List&lt;string&gt; inputData = new List&lt;string&gt;(); inputData.AddRange(valueArray); //If everything goes well close excel workbook xlWorkBookDB.Close(false, TestWorkbook1, null);</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/202981/Add-Excel-Range-to-Lists-without-looping-in-C/https://www.aspforums.net:443/Threads/202981/Add-Excel-Range-to-Lists-without-looping-in-C/Tue, 12 Jul 2016 06:06:31 GMTAdd Excel Range to Lists without looping in C#<p>Insted of using&nbsp;Microsoft.Office.Interop.Excel you can easily read the excel in oledb or openXml.</p> <ul style="list-style-type: undefined;"> <li class="header"><a title="Read Excel file using OLEDB Data Provider in C# .Net'a" href="http://www.aspsnippets.com/Articles/Read-Excel-file-using-OLEDB-Data-Provider-in-C-Net.aspx">Read Excel file using OLEDB Data Provider in C# .Net</a></li> <li class="header"><a title="Read and Import Excel data to DataTable using OpenXml in ASP.Net with C# and VB.Net'a" href="http://www.aspsnippets.com/Articles/Read-and-Import-Excel-data-to-DataTable-using-OpenXml-in-ASPNet-with-C-and-VBNet.aspx">Read and Import Excel data to DataTable using OpenXml in ASP.Net with C# and VB.Net</a></li> </ul> <p>&nbsp;</p> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/202981/Add-Excel-Range-to-Lists-without-looping-in-C/https://www.aspforums.net:443/Threads/202981/Add-Excel-Range-to-Lists-without-looping-in-C/Tue, 12 Jul 2016 08:50:17 GMTAdd Excel Range to Lists without looping in C#<p>Hi Dharmendr,</p> <p>I have (.xlsb) excel files therefore OLEDB does not work properly.</p> <p>OpenXml go through each rows. Which is not optimal if you have 200 workbooks and each workbook contains 70,000 rows and 70 columns of data.</p> <p>However I found a way:</p> <pre class="brush: csharp">var inputData = valueArray.Cast&lt;object&gt;().Select(Convert.ToString).ToList();</pre> <p>&nbsp;</p> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/202981/Add-Excel-Range-to-Lists-without-looping-in-C/https://www.aspforums.net:443/Threads/202981/Add-Excel-Range-to-Lists-without-looping-in-C/Tue, 12 Jul 2016 08:56:07 GMT