SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2005
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is there any way of telling how many worksheets the Excel doc contains?

    Hi guys

    I'm currently working on an ASP.NET application that reads in Excel data to a DataSet, is there any way of telling how many worksheets the Excel doc contains?

    Currently I'm using this code

    PHP Code:
    for(int i=0i<this.excelSheets.Lengthi++)
    {
       
    string strCommand "SELECT * FROM ["+
       
    this.excelSheets[i]+
       
    "$]";

       
    string strConnection =@"Provider=Microsoft.Jet.OLEDB.4.0;"+
       @
    " Data Source="+this.filePath+this.fileName+
       @
    ";"+
       @
    " Extended Properties=""Excel 8.0;"+
       @
    " HDR=YES;""";

       
    OleDbDataAdapter objDataAdapter = new OleDbDataAdapter(strCommand,strConnection);

       
    this.dataSetName.Tables.Add(this.excelSheets[i]);

       
    objDataAdapter.Fill(dataSetName,this.excelSheets[i]);

    I have to use a string array for each of the excel sheets but I dont really want to have to hardcode this for each excel doc I use

    Hope this makes sense

    Any help would be much appreciated

    Thanks in advance

    Tez

  2. #2
    I ♥ PHP
    Join Date
    Jul 2003
    Location
    Melbourne, Australia
    Posts
    579
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Tez,

    My only sollution would be to create an instance of the Excel application object in your application and then load the document and count the worksheets. The way you are doing it I do not believe there is a way sorry.

    Regards,
    Jordan

  3. #3
    SitePoint Zealot
    Join Date
    Sep 2005
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Jordan

    Thank you for your reply I didn't realise you could do that from a web app?

    I'll look into it


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •