Steamed Design

  • Random
  • Archive
  • RSS
  • Ask me anything

Excel Reader Writer (excel not required)

Ok as promised here it is a very simple(1 days work) wrapper for reading and writing excel files using 2007 Office System Driver: Data Connectivity Component. Below is an example function that shows what the class library can do. Remember to include a reference to the library in you project.

public void CorichExcel()
{
    string file = "C:/excel.xls";

    string sheet = "";

    try
    {
        //Gets a liost of sheets from the excel file
        string[] sheets = Corich.Excel.ReaderWriter.GetSheets(file);
        sheet = sheets[0];
    }
    catch(Exception ex)
    {
        MessageBox.Show(ex.Message);
        return;
    }
    
    //Check to see if the sheet exist
    if (Corich.Excel.ReaderWriter.SheetExists(file, sheet))
    {

        //gets a list of colums from the first sheet in the excel file
        string[] columns = Corich.Excel.ReaderWriter.GetColumns(file, sheet);

        //Loads the data in the first excel sheet into a data table
        DataTable data = Corich.Excel.ReaderWriter.Read(file);

        //Writes the data from the first sheet to a new excel file, currently only writes to xlsb files
        Corich.Excel.ReaderWriter.Write("C:\new_file.xlsb", data);

        //Writes the data from the first sheet to a new excel file in the temp directory then opens it, currently only writes to xlsb files
        Corich.Excel.ReaderWriter.WriteToTemp("new_file.xlsb", data, true);
    }

}

You can download the .dll and the source here the code is under the GNU GPL licence it would be nice to point people to my site if you use it.

  • 3 years ago
  • Comments
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

Recent comments

Blog comments powered by Disqus
← Previous • Next →

About

Avatar Thoughts and work form a software developer in his attempts to learn some new stuff.

Pages

  • Example Code
  • Photo's from my Phone
  • Alpine Parrot
  • PSN
  • Careers 2.0
  • Old Blog

Me, Elsewhere

  • Korich on Forrst
  • @korich on Twitter
  • Facebook Profile
  • Linkedin Profile
  • korich on github

Twitter

loading tweets…

  • RSS
  • Random
  • Archive
  • Ask me anything
  • Mobile
Effector Theme by Pixel Union