Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Merging Multiple Excel Tabs into a database

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Merging Multiple Excel Tabs into a database

    Hi All,

    I was wondering if there is a way to automatically import all tabs of an excel file into a database. I have a client that submitted a bunch of Excel Files, each have 15 or 20 tabs in them. They were generated by a tool that parcels out 65,000 lines to a tab and due to the size of the dataset just generates how many ever tabs it takes to takes to chunk up the data. If I do a Connection String I can specify a tab, one at a time... the regular Excel Import does not seem to like multi-tabbed files which would require me to break up the master file(s) into a file-per-tab.

    All tabs are formatted exactly alike, just continuing data.

    Regards,
    Keith
    Keith Weatherhead
    Discus Data, Ltd
    [email protected]

  • #2
    Re: Merging Multiple Excel Tabs into a database

    OK, so I figured out how to get ALPHADAO to do what I wanted, but the Genie ordered that tabs incorrectly, actually sorted on ASCII sequence, so I saved the function as XBasic, now to fix it for the correct sequence and I *should* be good to go, I hope....
    Keith Weatherhead
    Discus Data, Ltd
    [email protected]

    Comment


    • #3
      Re: Merging Multiple Excel Tabs into a database

      Probably easier to use ole to break the original spreadsheet into one tab per spreadsheet and then import all of them.

      Code:
      'sample usage - ex_splitter("c:\data\my_big_file.xls")
      'creates a csv file of each tab of docName in c:\temp
      'filename will be 'file tabname.csv
      FUNCTION ex_splitter AS L (docName AS C)
      	ex_splitter= .F.
      	Dim xlApp as p
      	Dim myCell as c
      	'concatenate spreadsheet name
      	Dim sht_name as c
      	sht_name = "Master"
      	
      	xlApp = ole.getobject("","Excel.Application")
      	xlApp.Workbooks.Open(docname)
      	'debug(1)
      	'xlApp.Visible = .T. 'comment this line out if you don't want to see Excel
      	IF xlApp.ActiveWorkbook.ReadOnly
      		ui_msg_box("Alert","Halting because file is read-only.",UI_OK)
      		xlapp.DisplayAlerts = .F.
      		xlApp.Workbooks.Close()
      		xlapp.DisplayAlerts = .T.
      		xlApp.Quit()
      		delete xlApp
      		exit function
      	END IF
      	shts = xlApp.Worksheets.Count
      	for qx = 1 to shts
      		xlApp.Worksheets(qx).Select()
      		chk = xlApp.ActiveSheet.Name
      		lastrow = xlApp.Activecell.SpecialCells("11").Row
      		lastcol = xlApp.Activecell.SpecialCells("11").Column
      		lastcell = xlindx_to_txt(lastcol)+lastrow
      		xlApp.Range("A1:"+lastcell).Select()
      		xlApp.Application.DisplayAlerts = .F.
      		xlApp.ActiveWorkbook.SaveAs("c:\temp\file "+chk+".csv",6,.F.)
      		xlApp.Workbooks.Close()
      		xlApp.Application.DisplayAlerts = .T.
      		xlApp.Workbooks.Open(docname)
      	next qx
      	xlApp.Quit()
      	Delete xlApp
      	ex_splitter = .T.
      END FUNCTION
      FUNCTION xlindx_to_txt AS C (colnum AS N )
        If Colnum > 26 Then
          xlindx_to_txt = Chr(Int((Colnum - 1) / 26) + 64) + Chr((mod((Colnum - 1),26) ) + 65)
        Else
          xlindx_to_txt = Chr(Colnum + 64)
        End If
      END FUNCTION
      There can be only one.

      Comment


      • #4
        Re: Merging Multiple Excel Tabs into a database

        There is a similar request posted here:

        http://msgboard.alphasoftware.com/al...mns-to-Records .

        Stan responded and so did I. You could modify the code I gave to work its way across the workbook, sheet by sheet, and then populate the table from the variable array.

        If you make the array large enough to capture the # of columns and rows in a sheet, loop through the code and then add the records to the table from the array, it should work.

        Just remember to clear the array after you have moved the data into the table.

        Tom

        Comment


        • #5
          Re: Merging Multiple Excel Tabs into a database

          Stan & Tom,

          THANX for your solutions... I will look at shortly. I was able to get out of this jam with A5's ALPHADAO Import, but not after several attempts to learn some of its finer points I had never had to use before.

          It was bad enough to have to go thru the spreadsheets tabs and fix the formatting to be sure it all converted the same way, but then I got a few bruises from DAO, too. I am looking to come up with a method/tool for doing this in a more generalized method as it seems to be coming up over and over again... this particular project brought to a head due to several files with as many as 20 tabs each. My finger tips are numb at the moment, so I figured it was definitely time to put a tool in place going forward.

          Again, many thanx for the thoughts and recommendations !!!

          Regards,
          Keith
          Keith Weatherhead
          Discus Data, Ltd
          [email protected]

          Comment


          • #6
            Re: Merging Multiple Excel Tabs into a database

            Too bad they don't send you a single csv file instead...
            Al Buchholz
            Bookwood Systems, LTD
            Weekly QReportBuilder Webinars Thursday 1 pm CST

            Occam's Razor - KISS
            Normalize till it hurts - De-normalize till it works.
            Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
            When we triage a problem it is much easier to read sample systems than to read a mind.
            "Make it as simple as possible, but not simpler."
            Albert Einstein

            http://www.iadn.com/images/media/iadn_member.png

            Comment


            • #7
              Re: Merging Multiple Excel Tabs into a database

              Agreed, sometimes they think they are being helpful... sometimes it is just the way their systems output the data automatically.
              I never know what is come at me, however it is presented, I have to make it work if at all possible, sometimes I just have to go
              back to them and have them get me an IT contact so I can find out what other options exist.

              Keith
              Keith Weatherhead
              Discus Data, Ltd
              [email protected]

              Comment


              • #8
                Re: Merging Multiple Excel Tabs into a database

                Good thought, Al. Should be easy to concatenate the csv files into one using SAVE_TO_FILE(). More tomorrow.
                There can be only one.

                Comment


                • #9
                  Re: Merging Multiple Excel Tabs into a database

                  Originally posted by Stan Mathews View Post
                  Good thought, Al. Should be easy to concatenate the csv files into one using SAVE_TO_FILE(). More tomorrow.
                  I originally was referring to the source file to get CSV instead of Excel but Stan you're right converting the multi-tabbed Excel to a single CSV might be easier.
                  Al Buchholz
                  Bookwood Systems, LTD
                  Weekly QReportBuilder Webinars Thursday 1 pm CST

                  Occam's Razor - KISS
                  Normalize till it hurts - De-normalize till it works.
                  Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
                  When we triage a problem it is much easier to read sample systems than to read a mind.
                  "Make it as simple as possible, but not simpler."
                  Albert Einstein

                  http://www.iadn.com/images/media/iadn_member.png

                  Comment


                  • #10
                    Re: Merging Multiple Excel Tabs into a database

                    Made the modification.

                    Code:
                    'sample usage - ex_splitter("c:\data\my_big_file.xls")
                    'creates a csv file of each tab of docName in c:\temp
                    'filename will be 'file tabname.csv
                    FUNCTION ex_splitter AS L (docName AS C)
                    	ex_splitter= .F.
                    	Dim xlApp as p
                    	Dim myCell as c
                    	Dim to_combine as C
                    	to_combine = ""
                    	'concatenate spreadsheet name
                    	Dim sht_name as c
                    	sht_name = "Master"
                    	
                    	xlApp = ole.getobject("","Excel.Application")
                    	xlApp.Workbooks.Open(docname)
                    	'debug(1)
                    	'xlApp.Visible = .T. 'comment this line out if you don't want to see Excel
                    	IF xlApp.ActiveWorkbook.ReadOnly
                    		ui_msg_box("Alert","Halting because file is read-only.",UI_OK)
                    		xlapp.DisplayAlerts = .F.
                    		xlApp.Workbooks.Close()
                    		xlapp.DisplayAlerts = .T.
                    		xlApp.Quit()
                    		delete xlApp
                    		exit function
                    	END IF
                    	shts = xlApp.Worksheets.Count
                    	for qx = 1 to shts
                    		xlApp.Worksheets(qx).Select()
                    		chk = xlApp.ActiveSheet.Name
                    		lastrow = xlApp.Activecell.SpecialCells("11").Row
                    		lastcol = xlApp.Activecell.SpecialCells("11").Column
                    		lastcell = xlindx_to_txt(lastcol)+lastrow
                    		xlApp.Range("A1:"+lastcell).Select()
                    		xlApp.Application.DisplayAlerts = .F.
                    		fil_name = "c:\temp\file "+chk+".csv"
                    		xlApp.ActiveWorkbook.SaveAs(fil_name,6,.F.)
                    		xlApp.Workbooks.Close()
                    		xlApp.Application.DisplayAlerts = .T.
                    		to_combine = to_combine +fil_name+crlf()
                    		xlApp.Workbooks.Open(docname)
                    	next qx
                    	xlApp.Quit()
                    	Delete xlApp
                    	combined_count = line_count(to_combine)
                    	combined = file.to_string(word(to_combine,1,crlf()))
                    	save_to_file(combined,"c:\temp\xlscombined.csv")
                    	for qz = 2 to combined_count
                    		next_file = file.to_string(word(to_combine,qz,crlf()))
                    		save_to_file(next_file,"c:\temp\xlscombined.csv",.T.)
                    	next qz
                    	ex_splitter = .T.
                    END FUNCTION
                    FUNCTION xlindx_to_txt AS C (colnum AS N )
                      If Colnum > 26 Then
                        xlindx_to_txt = Chr(Int((Colnum - 1) / 26) + 64) + Chr((mod((Colnum - 1),26) ) + 65)
                      Else
                        xlindx_to_txt = Chr(Colnum + 64)
                      End If
                    END FUNCTION
                    There can be only one.

                    Comment


                    • #11
                      Re: Merging Multiple Excel Tabs into a database

                      Way Cool, Stan !!
                      Now all I have to do is put a File Chooser Front-End and it will be really useful for my purposes...

                      Thanx,
                      Keith
                      Keith Weatherhead
                      Discus Data, Ltd
                      [email protected]

                      Comment


                      • #12
                        Re: Merging Multiple Excel Tabs into a database

                        Sweet....

                        Keith let us know if the provider can give you a single CSV.

                        It might save you a lot of work and future maintenance. Also will leave an impression here on the messageboard that excel transfers are limiting and data transfers are easier with CSV files.

                        (in spite of Stan's great work...)
                        Al Buchholz
                        Bookwood Systems, LTD
                        Weekly QReportBuilder Webinars Thursday 1 pm CST

                        Occam's Razor - KISS
                        Normalize till it hurts - De-normalize till it works.
                        Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
                        When we triage a problem it is much easier to read sample systems than to read a mind.
                        "Make it as simple as possible, but not simpler."
                        Albert Einstein

                        http://www.iadn.com/images/media/iadn_member.png

                        Comment


                        • #13
                          Re: Merging Multiple Excel Tabs into a database

                          The way it is written you will have the column headers written to the csv for each tab in the original spreadsheet. We can eliminate that with

                          Code:
                          for qz = 2 to combined_count
                          		next_file = file.to_string(word(to_combine,qz,crlf()))
                          		[COLOR="#FF8C00"]next_file = *LINE_REMOVE(next_file,1,1)[/COLOR]
                          		save_to_file(next_file,"c:\temp\xlscombined.csv",.T.)
                          	next qz
                          There can be only one.

                          Comment


                          • #14
                            Re: Merging Multiple Excel Tabs into a database

                            Al,

                            Unfortunately it is NOT a single provider, we doing a specialize form of auditing for many clients all over the country and Canada. EVERYONE and I mean everyone gives us data in differing layouts, formats, file types, you name it... I have to deal with it however it comes at us. I am finally getting tired of doing things over and over and really starting to automate and make specialty tools that simply my life... the whole purpose of using a tool such as A5. I use about half a dozen different tools to accomplish what I need... there is not a single tools out there that can do all of what I need to accomplish. Once the data is in A5 or Excel my life becomes a lot easier, but you would not believe the ways the data arrives in the first place.

                            Regards,
                            Keith


                            Originally posted by Al Buchholz View Post
                            Sweet....

                            Keith let us know if the provider can give you a single CSV.

                            It might save you a lot of work and future maintenance. Also will leave an impression here on the messageboard that excel transfers are limiting and data transfers are easier with CSV files.

                            (in spite of Stan's great work...)
                            Keith Weatherhead
                            Discus Data, Ltd
                            [email protected]

                            Comment


                            • #15
                              Re: Merging Multiple Excel Tabs into a database

                              Stan,

                              You are absolutely correct... I was going to make this kind of modification cause as I read thru your code I knew this would be an issue to side step.
                              Thanx Again !!!

                              Regards,
                              Keith

                              Originally posted by Stan Mathews View Post
                              The way it is written you will have the column headers written to the csv for each tab in the original spreadsheet. We can eliminate that with

                              Code:
                              for qz = 2 to combined_count
                              		next_file = file.to_string(word(to_combine,qz,crlf()))
                              		[COLOR="#FF8C00"]next_file = *LINE_REMOVE(next_file,1,1)[/COLOR]
                              		save_to_file(next_file,"c:\temp\xlscombined.csv",.T.)
                              	next qz
                              Keith Weatherhead
                              Discus Data, Ltd
                              [email protected]

                              Comment

                              Working...
                              X