Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What about using <a href="https://github.com/ExcelDataReader/ExcelDataReader" rel="noreferrer">Excel Data Reader</a> (previously hosted <a href="http://exceldatareader.codeplex.com/" rel="noreferrer">here</a>) an open source project on codeplex? Its works really well for me to export data from excel sheets. </p> <p>The sample code given on the link specified:</p> <pre><code>FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read); //1. Reading from a binary Excel file ('97-2003 format; *.xls) IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream); //... //2. Reading from a OpenXml Excel file (2007 format; *.xlsx) IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream); //... //3. DataSet - The result of each spreadsheet will be created in the result.Tables DataSet result = excelReader.AsDataSet(); //... //4. DataSet - Create column names from first row excelReader.IsFirstRowAsColumnNames = true; DataSet result = excelReader.AsDataSet(); //5. Data Reader methods while (excelReader.Read()) { //excelReader.GetInt32(0); } //6. Free resources (IExcelDataReader is IDisposable) excelReader.Close(); </code></pre> <p><strong>UPDATE</strong></p> <p>After some search around, I came across this article: <a href="http://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=9992" rel="noreferrer">Faster MS Excel Reading using Office Interop Assemblies</a>. The article only uses <code>Office Interop Assemblies</code> to read data from a given Excel Sheet. The source code is of the project is there too. I guess this article can be a starting point on what you trying to achieve. See if that helps</p> <p><strong>UPDATE 2</strong></p> <p>The code below takes an <code>excel workbook</code> and reads all values found, for each <code>excel worksheet</code> inside the <code>excel workbook</code>.</p> <pre><code>private static void TestExcel() { ApplicationClass app = new ApplicationClass(); Workbook book = null; Range range = null; try { app.Visible = false; app.ScreenUpdating = false; app.DisplayAlerts = false; string execPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase); book = app.Workbooks.Open(@"C:\data.xls", Missing.Value, Missing.Value, Missing.Value , Missing.Value, Missing.Value, Missing.Value, Missing.Value , Missing.Value, Missing.Value, Missing.Value, Missing.Value , Missing.Value, Missing.Value, Missing.Value); foreach (Worksheet sheet in book.Worksheets) { Console.WriteLine(@"Values for Sheet "+sheet.Index); // get a range to work with range = sheet.get_Range("A1", Missing.Value); // get the end of values to the right (will stop at the first empty cell) range = range.get_End(XlDirection.xlToRight); // get the end of values toward the bottom, looking in the last column (will stop at first empty cell) range = range.get_End(XlDirection.xlDown); // get the address of the bottom, right cell string downAddress = range.get_Address( false, false, XlReferenceStyle.xlA1, Type.Missing, Type.Missing); // Get the range, then values from a1 range = sheet.get_Range("A1", downAddress); object[,] values = (object[,]) range.Value2; // View the values Console.Write("\t"); Console.WriteLine(); for (int i = 1; i &lt;= values.GetLength(0); i++) { for (int j = 1; j &lt;= values.GetLength(1); j++) { Console.Write("{0}\t", values[i, j]); } Console.WriteLine(); } } } catch (Exception e) { Console.WriteLine(e); } finally { range = null; if (book != null) book.Close(false, Missing.Value, Missing.Value); book = null; if (app != null) app.Quit(); app = null; } } </code></pre> <p>In the above code, <code>values[i, j]</code> is the value that you need to be added to the <code>dataset</code>. <code>i</code> denotes the row, whereas, <code>j</code> denotes the column. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload