Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Load data from Excel which has columns in multiple rows

Load data from Excel which has columns in multiple rows

Scheduled Pinned Locked Moved Database
algorithmsquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    indian143
    wrote on last edited by
    #1

    Hi All, I have an Excel file in which there are multiple sheets and its columns are spread in multiple rows like a parent has multiple children and those children have their children. How can I load this data in to a table sheet by sheet, means for each load if it loads from one sheet that's fine but important thing here is columns are spread into multiple rows. I am also searching, but any link, any suggestion or code snippet is going to be very very helpful. Thanks in advance.

    Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."

    L 1 Reply Last reply
    0
    • I indian143

      Hi All, I have an Excel file in which there are multiple sheets and its columns are spread in multiple rows like a parent has multiple children and those children have their children. How can I load this data in to a table sheet by sheet, means for each load if it loads from one sheet that's fine but important thing here is columns are spread into multiple rows. I am also searching, but any link, any suggestion or code snippet is going to be very very helpful. Thanks in advance.

      Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      See Working with MS Excel(xls / xlsx) Using MDAC and Oledb[^].

      I 1 Reply Last reply
      0
      • L Lost User

        See Working with MS Excel(xls / xlsx) Using MDAC and Oledb[^].

        I Offline
        I Offline
        indian143
        wrote on last edited by
        #3

        Sorry I didn't mention it may be but I want to do it SQL Server script. So I am trying in the following way

        SELECT * INTO #Servxxx
        FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
        'Excel 12.0 Xml; HDR=YES; IMEX=1;
        Database=D:\Servxxx.xls',
        [Servxxx First Sheet$]);

        It is giving me the following error

        OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" returned message "The Microsoft Access database engine could not find the object 'D:\Servxxx.xls'. Make sure the object exists and that you spell its name and the path name correctly. If 'D:\Servxxx.xls' is not a local object, check your network connection or contact the server administrator.".
        Msg 7303, Level 16, State 1, Line 10
        Cannot initialize the data source object of OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)".

        It is saying file is not there, but file is there and it is erroring out with link server etc.

        Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."

        Richard DeemingR 1 Reply Last reply
        0
        • I indian143

          Sorry I didn't mention it may be but I want to do it SQL Server script. So I am trying in the following way

          SELECT * INTO #Servxxx
          FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
          'Excel 12.0 Xml; HDR=YES; IMEX=1;
          Database=D:\Servxxx.xls',
          [Servxxx First Sheet$]);

          It is giving me the following error

          OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" returned message "The Microsoft Access database engine could not find the object 'D:\Servxxx.xls'. Make sure the object exists and that you spell its name and the path name correctly. If 'D:\Servxxx.xls' is not a local object, check your network connection or contact the server administrator.".
          Msg 7303, Level 16, State 1, Line 10
          Cannot initialize the data source object of OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)".

          It is saying file is not there, but file is there and it is erroring out with link server etc.

          Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          Is D: a local drive, or a mapped network drive? Does the SQL service account have permission to access the file?


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          I 1 Reply Last reply
          0
          • Richard DeemingR Richard Deeming

            Is D: a local drive, or a mapped network drive? Does the SQL service account have permission to access the file?


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            I Offline
            I Offline
            indian143
            wrote on last edited by
            #5

            Hey Rick, thanks I got it sort out my friend here is the sample one may be somebody has the same issue. SELECT * INTO #xxxxxxs FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0 Xml; HDR=YES; IMEX=1; Database=C:\xxxxxxx\Dont Remove ThisFolder\xxxxxxs.xlsx', 'SELECT * FROM [Back xxxxx$]'); I have a question here, do we have any way to copy the existing schema structure into a table variable, along with an identity column?

            Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups