Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • ice123456 3 posts 23 karma points
    Dec 13, 2010 @ 06:41
    ice123456
    0

    how to export data from spreadsheet to datatable?

    Hi experts,

    i want to know what's the best way to export data from spreadsheet to datatable? maybe, any way that can export data from spreadsheet to datatable.

    Thanks for any answers.

  • Sascha Wolter 615 posts 1101 karma points
    Dec 13, 2010 @ 07:47
    Sascha Wolter
    0

    Hi,

    it pretty much depends on the format of your 'spreadsheet'. If it's a CSV file then things are quite easy, you could do something like:

    StreamReader streamReader = File.OpenText(_sImportFilePath);

    string sFileContents = streamReader.ReadToEnd();

    string[] sArrRowDelimeter = new string[] { "\r\n" };

    string[] sArrFileRows = sFileContents.Split(sArrRowDelimeter, StringSplitOptions.RemoveEmptyEntries);

    int iResultCount = sArrFileRows.Length;
    if (iResultCount > 1)
    {
        for (int i = 1; i < sArrFileRows.Length; i++)
        {
            string[] sArrRowColumns = sArrFileRows[i].Split(',');
            //do something with the data; you most likely have to clean up the input a bit
        }
    }

    For anything more complicated (e.g. Excel format 2007/2010) I would probably spend some money on one of the out-of-the-box .Net dlls like the one you have linked above, it's money well spend IMO.

    Cheers, Sascha

Please Sign in or register to post replies

Write your reply to:

Draft