How to read excel file using c#

Today I am going to show you how read excel file using c# and create folders based on excel file. Sometimes we may want to create many folders/sub folders based on business requirement and copy files into respective directory. So I am going to show how to do this using c# .net language. For this project i am using

  • Microsoft Visual Studio 2013
  • .net framework 4.5
  • ExcelDataReader library ( You can find it here)
  • Sample excel file which contain sample data set

Here is my project structure.

structure
Project Structure

Sample output

sample_output_parent
Parent folders
sample_output_child
Child folders

I have created sample console application to perform this task. I haven’t add exception handling for this code and feel free to optimize code and use it.

using Excel;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FolderProject
{
    /// <summary>
    /// Author : Damith Wanninayake
    /// Excel 4.5 library url:https://github.com/ExcelDataReader/ExcelDataReader
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            FileStream stream = File.Open(ConfigurationManager.AppSettings["sourceFile"], FileMode.Open, FileAccess.Read);
            string basePath = ConfigurationManager.AppSettings["basePath"];

            // Reading from a OpenXml Excel file (2007 format; *.xlsx)
            IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);

            // DataSet - Create column names from first row
            excelReader.IsFirstRowAsColumnNames = true;
            DataSet result = excelReader.AsDataSet();

            // Getting distinct values
            var distinctValues = result.Tables[0].AsEnumerable()
                        .Select(row => new
                        {
                            Mem = row.Field<double>("Mem#"),

You can find the completed project which contains excel file in here. Please note that i am not the author of the excel file.

What is jsPlumb

jsPlumb is a data visualization library available for most popular JavaScript libraries like jQuery, MooTools,Vanilla JS, YUI3. There are lot of features available on jsPlumb and has lots of examples over internet and they have a good documentation.

jsPlumb provides a means for a developer to visually connect elements on their web pages. It uses SVG or Canvas in modern browsers, and VML on IE 8 and below. The latest version is 1.6.4.

 

The project started out life on Google Code and was hosted there up until April 30, 2013. From May 1st, 2013, jsPlumb lives on GitHub only.

 

If you’re new to jsPlumb, please do take the time to read the documentation. There are a few integration issues that you should be aware of: z-index needs special attention, for example.

You can find running demos in here (http://jsplumb.org/demo/home/jquery.html) and licensed under the MIT license.

Browser Compatibility

jsPlumb runs on everything from IE6 up. There are some caveats, though, because of various browser/library bugs:

  • jQuery 1.6.x and 1.7.x have a bug in their SVG implementation for IE9 that causes hover events to not get fired.
  • jQuery 2.0 does not support IE 6,7 or 8.
  • Safari 5.1 has an SVG bug that prevents mouse events from being passed through the transparent area of an SVG element (Safari 6.x does not seem to have the same problem)
  • MooTools has a bug when using SVG in Firefox 11

 

Go ahead and try this awesome library for one of your projects

 

References

 

 

Develop high quality software using NDepend

I just tried this tool and it looks pretty powerful, I still have to dig further in it.It has lots of features like

  • Code Rule and Code Query over LINQ (CQLinq)
  • Trend Monitoring
  • Harness Test Coverage Data
  • Code Quality, 82 Code Metrics
  • Explore Existing Architecture
  • Detect Dependency Cycles
  • Compare Builds and Code Diff
  • Compare Builds and Code Diff
  • Complexity and Diagrams
  • Continuous Integration Reporting
  • Warnings on Build Process Health
  • NDepend.API and Power Tools
  • Real-World Proof

If you are really interested to increase the quality of your product, you better to try this tool. NDepend offers a wide range of features to let the user analyze a code base.
It is often described as a Swiss Army Knife for .NET developers.

http://www.ndepend.com/Default.aspx