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

Creating Multiple Excel Worksheets from one export Script

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

    Creating Multiple Excel Worksheets from one export Script

    Is it possible to create multiple worksheets in Excel from one Export Script in A5? In A5 reports, you can break the information according to a field specified within a table. For example you might make the break on records by a client name, thereby creating a new report for each client. We need to do this on an export operation from within a script. I've created a query for the necessary information and then an export. I know I can have it loop through the export operation for the records but is it possible to tell A5 to create a new excel file for each Client in the query, basically grouping the queried info for each client in a different Excel worksheet?

    To be honest I've never tried anything like this and am at a loss. I could not find anything in the message board regarding this type of Export. Thanks for reading the post and any or all ideas are welcome.

    Scott

    #2
    Re: Creating Multiple Excel Worksheets from one export Script

    Looks like were in the same boat... I was able to use a5_AlphaDAO_Export() to send data from multiple tables to an Excel worksheet. Works great, each table has its own sheet. In the genie you can set arguments to prompt for the value for the filter to use. But now I want to add more tables from a different database (tables have the same names) and it looks like the only option is to create separate xls files and then merge them into new sheets. According to Excel all the files must be in the same folder. I was hoping there was a way to edit the Xbasic the genie creates so I can use the same script and just change the file name. But the genie only creates a new file or uses an existing one. So I will add my question to yours - how do you do that using Xbasic?

    Oops, I see you are using v5 - I am on v11. Perhaps someone will be able to help us both...?
    Last edited by MoGrace; 01-22-2015, 08:13 PM.
    Robin

    Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

    Comment


      #3
      Re: Creating Multiple Excel Worksheets from one export Script

      We will be upgrading to V11 in 2 weeks. I had some major problems in November and had to rebuild the db. I've just been making sure it is now running smoothly with no major glitches, but will be upgrading in 2 weeks.

      Comment


        #4
        Re: Creating Multiple Excel Worksheets from one export Script

        We're using ver 10.5, and we have a function to grab data from a specified sheet in a workbook. I don't see why the reverse couldn't be done. Maybe I'm oversimplifying it, but where I assign an array variable to an excel cell, I don't see why you couldn't just reverse the equation. You would need to have a "save" for the workbook, but I think it could be done.

        Code:
        'Date Created: 17-Jul-2013 02:57:48 PM
        'Last Updated: 14-Nov-2014 10:11:10 AM
        'Created By  : Thomas Henkel
        'Updated By  : Stephen Andrews
        ' Variables passed:
        ' Filename = Name of excel workbook
        ' First row is numeric = first row to select  - usually 1 unless you have header rows
        ' First col is numeric, usually 1
        ' Data_Array is the pointer to the array from the calling script
        ' Sheet is numeric value of which sheet in the workbook to select
        Function get_excel_data as V (Filename as C, First_Row as N, First_Col as N, Data_Array as P, Sheet as N)
            dim MyObject as P
            dim row as N
            dim col as N
            dim rows as N
            dim cols as N
            dim cell as C
            dim temp as C
            cols = Data_Array.size(2)
            rows = Data_Array.size(1)
            on error goto quitting
            MyObject = ole.getobject("","Excel.Application")
        	MyObject.Workbooks.Open(Filename)
           MyObject.Worksheets(Sheet).Select()    'This was commented out.  Steve uncommented it on 11/14/14.
            for row = First_Row to  rows
                for col = First_Col to cols
                    cell = get_col(col) + row
                    [COLOR="#FF0000"]Data_Array[row,col] = MyObject.activesheet.Cells.Range(cell)[/COLOR]
                next col
            next row
        quitting:
        
        '  Somehow you would need to put a "save" here
        
            MyObject.Workbooks.close()
            delete MyObject
        end function
        Tom

        Comment


          #5
          Re: Creating Multiple Excel Worksheets from one export Script

          ' Somehow you would need to put a "save" here
          MYObject.ActiveWorkbook.SaveAs("drive_path_name_extension_in_quotes",-4143)
          MyObject.Workbooks.close()
          MyObject.Quit()


          -4143 is latest version in Excel 2003
          would use
          70 for Excel 97-2003 in Excel 2013, etc.
          6 is csv.

          .getobject() is Alpha V6 and later. I think V5 would be

          MyObject = ole.create("Excel.Application")
          Last edited by Stan Mathews; 01-23-2015, 05:20 PM.
          There can be only one.

          Comment


            #6
            Re: Creating Multiple Excel Worksheets from one export Script

            Tom,

            I certainly don't mean to be sniping at your post. Just want to add that it uses a function get_col() to translate the column index (numeric) to a letter. I do something similar and in the absence of your translation function I offer.

            Code:
            FUNCTION get_col AS C (colnum AS N )
            	'returns a character column reference from its numeric index
              If Colnum > 26 Then
                get_col = Chr(Int((Colnum - 1) / 26) + 64) + Chr((mod((Colnum - 1),26) ) + 65)
              Else
                get_col = Chr(Colnum + 64)
              End If
            END FUNCTION
            There can be only one.

            Comment


              #7
              Re: Creating Multiple Excel Worksheets from one export Script

              Stan, just out of curiosity, do you think it would be possible to use a variable calling on the "Client" field so that on this line,"MYObject.ActiveWorkbook.SaveAs("drive_path_name_extension_in_quotes",-4143)" the variable could be used where the name would normally appear in the path? Hopefully, that way with a loop, it might possibly save each workbook to the "client" name. Just wondering if you think this may be viable or am I over simplifying my thinking?
              Thanks....Scott

              Comment


                #8
                Re: Creating Multiple Excel Worksheets from one export Script

                Do it all the time. Just had the hard-coded expression there to illustrate what is needed.

                Be careful to construct a legal filename.

                cust = "ABC Co."
                file_name = "C:\tempfiles\\"+cust+"_wk_ending_"+date()+".xls"
                ? file_name
                = "C:\tempfiles\ABC Co._wk_ending_01/26/2015.xls"


                Looks ok but forward slashes aren't legal. You'll want something like

                file_name = "C:\tempfiles\\"+cust+_"wk_ending_"+dtoc(date(),"6-")+".xls"
                ? file_name
                = "C:\tempfiles\ABC Co._wk_ending_01-26-15.xls"
                There can be only one.

                Comment


                  #9
                  Re: Creating Multiple Excel Worksheets from one export Script

                  Thanks Stan.... I appreciate all your help.

                  Comment


                    #10
                    Re: Creating Multiple Excel Worksheets from one export Script

                    I'm having a major brain fade here. The script below works..... sort of. It will go to the first record that satisfies the filter criteria and creates the Excel file just fine. Unfortunately, it stops at the first record that satisfies the criteria. I know I'm missing something simple to tell it to run the Query and continue to the next client that satisfies the query, and so on. What am I missing?

                    dim tbl as P
                    dim cvar as C


                    tbl = table.open("New_Invoicing")

                    cvar = (New_Invoicing->Client)

                    'debug(1)



                    query.description = ""
                    query.order = "CLIENT+DATE"
                    query.filter = "CLIENT = (cvar) .AND. INVOICE_AMOUNT1-CHECK1-CHECK2-CHECK3-CHECK4>0"
                    query.options = "I"
                    tbl.query_create()

                    WHILE .NOT. tbl.Fetch_EOF()

                    tbl.batch_Begin()


                    export.type = 4
                    export.names = .T.
                    export.file = "\\amesrv\E\("+cvar+").xls"
                    export.options = ""
                    export.field_sep = ""
                    export.record_sep = ""
                    export.fields = 8
                    export.field1 = "new_invoicing->client"
                    export.field2 = "new_invoicing->date"
                    export.field3 = "new_invoicing->invoice_number1"
                    export.field4 = "new_invoicing->invoice_amount1"
                    export.field5 = "new_invoicing->date6"
                    export.field6 = "new_invoicing->invoice_number2"
                    export.field7 = "new_invoicing->invoice_amount2"
                    export.field8 = "new_invoicing->check5"

                    tbl.export()

                    tbl.fetch_Next()

                    END WHILE

                    tbl.batch_end()

                    SCRATCH THAT... Here is the correct script I'm using:

                    dim tbl as P
                    dim cvar as C


                    tbl = table.open("New_Invoicing")

                    cvar = (New_Invoicing->Client)

                    'debug(1)

                    WHILE .NOT. tbl.Fetch_EOF()

                    tbl.batch_Begin()



                    query.description = ""
                    query.order = "CLIENT+DATE"
                    query.filter = "CLIENT = (cvar) .AND. INVOICE_AMOUNT1-CHECK1-CHECK2-CHECK3-CHECK4>0"
                    query.options = "I"
                    tbl.query_create()




                    export.type = 4
                    export.names = .T.
                    export.file = "\\amesrv\E\("+cvar+").xls"
                    export.options = ""
                    export.field_sep = ""
                    export.record_sep = ""
                    export.fields = 8
                    export.field1 = "new_invoicing->client"
                    export.field2 = "new_invoicing->date"
                    export.field3 = "new_invoicing->invoice_number1"
                    export.field4 = "new_invoicing->invoice_amount1"
                    export.field5 = "new_invoicing->date6"
                    export.field6 = "new_invoicing->invoice_number2"
                    export.field7 = "new_invoicing->invoice_amount2"
                    export.field8 = "new_invoicing->check5"

                    tbl.export()

                    tbl.fetch_Next()

                    END WHILE

                    tbl.batch_end()

                    Comment


                      #11
                      Re: Creating Multiple Excel Worksheets from one export Script

                      You're not changing the cvar contents. Probably want something like......

                      Code:
                      dim tbl as P
                      dim cvar as C
                      tbl = table.open("New_Invoicing")
                      tbl.order("client")'put table in client order so we can skip over multiple instances and export only once per client
                      tbl.fetch_first()
                      tbl.batch_Begin()
                      WHILE .NOT. tbl.Fetch_EOF()
                      	cvar = tbl.client
                      	query.description = ""
                      	query.order = "CLIENT+DATE"
                      	query.filter = "CLIENT = (cvar) .AND. INVOICE_AMOUNT1-CHECK1-CHECK2-CHECK3-CHECK4>0"
                      	query.options = "I"
                      	tbl.query_create()
                      	export.type = 4
                      	export.names = .T.
                      	export.file = "\\amesrv\E\("+cvar+").xls"
                      	export.options = ""
                      	export.field_sep = ""
                      	export.record_sep = ""
                      	export.fields = 8
                      	export.field1 = "new_invoicing->client"
                      	export.field2 = "new_invoicing->date"
                      	export.field3 = "new_invoicing->invoice_number1"
                      	export.field4 = "new_invoicing->invoice_amount1"
                      	export.field5 = "new_invoicing->date6"
                      	export.field6 = "new_invoicing->invoice_number2"
                      	export.field7 = "new_invoicing->invoice_amount2"
                      	export.field8 = "new_invoicing->check5"
                      	tbl.export()
                      	while tbl.client = cvar .and. .not. tbl.fetch_eof()
                      	tbl.fetch_Next()
                      	end while
                      END WHILE
                      tbl.batch_end()
                      tbl.close()
                      Last edited by Stan Mathews; 01-26-2015, 07:50 PM.
                      There can be only one.

                      Comment


                        #12
                        Re: Creating Multiple Excel Worksheets from one export Script

                        Thanks Stan. Works except it is still only creating one excel file for the first record. Doesn't seem to be fetching the next record according to the "cvar" call out and creating an excel file for it or the following records. I see what you meant about not changing the "cvar" contents.

                        Comment


                          #13
                          Re: Creating Multiple Excel Worksheets from one export Script

                          Perhaps after the query is created, that's when I should be fetching the next record instead of fetching the next record and running the query each time. What do you think?

                          Comment


                            #14
                            Re: Creating Multiple Excel Worksheets from one export Script

                            On my tablet at the moment. Will take another look shortly.
                            There can be only one.

                            Comment


                              #15
                              Re: Creating Multiple Excel Worksheets from one export Script

                              No prob..... Thanks and I'm just spit balling here. I thought maybe we should be fetching the next records for the Export and only run the Query once.... if that makes any sense.

                              Comment

                              Working...
                              X