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

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

    Don't think so. We have to

    order by client
    get the client identifier
    query for that client
    export
    skip over that client's additional records
    get the next client
    repeat
    There can be only one.

    Comment


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

      OK......

      Comment


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

        Filter doesn't look right. Try it as

        query.filter = "CLIENT = "+quote(cvar)+" .AND. INVOICE_AMOUNT1-CHECK1-CHECK2-CHECK3-CHECK4>0"
        There can be only one.

        Comment


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

          OK, I'll give that a try.

          Comment


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

            Result is the same... Exports first record only. Same result with the filter before changed. I need to leave for the day but will be back on this either tomorrow or Thursday. Thanks again for all your help.

            Comment


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

              This works fine in AlphaSports. It seems the same process as you're using. Exports multiple dates and creates a file for each.

              Code:
              tbl = table.open("invoice_header")
              tbl.order("date")
              tbl.fetch_first()
              
              while .not. tbl.fetch_eof()
              	dt = tbl.date
              	export_filename = "c:\temp\("+cdate(dt)+").asc"
              	a_tbl = table.open("Invoice_Header")
              	ON ERROR GOTO ERROR2601201519050578
              	
              	
              	query.order = "recno()"
              	query.filter = "cdate(Date)  = "+quote(cdate(dt))
              	query.options = "I"
              	query.Description = "Temporary Query"
              	i_indx = a_tbl.query_create()
              	
              	export.type = 0
              	export.names = .T.
              	export.file = export_filename
              	export.options = ""
              	export.field_sep = ","
              	export.record_sep = "<CR><LF>"
              	export.fields = 10
              	export.field1 = "invoice_number"
              	export.field2 = "customer_id"
              	export.field3 = "date"
              	export.field4 = "sales_rep"
              	export.field5 = "delivery_by"
              	export.field6 = "pay_method"
              	export.field7 = "sales_tax"
              	export.field8 = "discount"
              	export.field9 = "cc_number"
              	export.field10 = "cc_expiration"
              	
              	a_tbl.export()
              	
              	
              	GOTO CONTINUE2601201519050578
              	ERROR2601201519050578:
              	ON ERROR GOTO 0
              	ui_msg_box("Error","Error running Export Operation"+crlf()+error_text_get())
              	END
              	CONTINUE2601201519050578:
              	a_tbl.close()
              	while .not. tbl.fetch_eof() .and. tbl.date = dt
              		tbl.fetch_next()
              	end while
              end while
              tbl.close()
              There can be only one.

              Comment


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

                Thanks Stan. I'll give it a try as soon as I'm back in the office.

                Comment


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

                  Found the problem. Since we were querying the table pointer for a single client the .fetch_eof() was satisfied.
                  we need a second table instance and second pointer for the export/query.

                  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
                  	a_tbl = table.open("New_Invoicing")
                  	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"
                  	a_tbl.export()
                          a_tbl.close()
                  	while tbl.client = cvar .and. .not. tbl.fetch_eof()
                  	tbl.fetch_Next()
                  	end while
                  END WHILE
                  tbl.batch_end()
                  tbl.close()
                  There can be only one.

                  Comment


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

                    Thanks Stan. That makes sense. I'll hop on it Thursday morning when I get back in the office. So the "A_table" reference is the second instance opened of the original table. I doubt if I would have caught that. Actually I didn't realize that a second instance would need to be opened. Thanks for catching that. And btw, this Saturday I'll be upgrading to V11.
                    Last edited by draxx2755; 01-27-2015, 03:32 PM.

                    Comment


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

                      Here's a commented version of the code. I also removed the New_Invoicing-> which is not necessary. Since you're only dealing with the one table and you specify the table with a_tbl = table.open("New_Invoicing") you don't need to specify it again when naming the fields.

                      Code:
                      dim tbl as P
                      dim cvar as C
                      'open the New_Invoicing table to get client id numbers
                      tbl = table.open("New_Invoicing")
                      'put table in client order so we can skip over multiple instances and export only once per client
                      tbl.order("client")
                      'start at the first client id found
                      tbl.fetch_first()
                      tbl.batch_Begin()
                      WHILE .NOT. tbl.Fetch_EOF()
                      	'read theclient id of the current record and store that to the cvar variable
                      	cvar = tbl.client
                      	'open a second instance of the table for the exporting source
                      	a_tbl = table.open("New_Invoicing")
                      	'set options and query for the client id obtained above
                      	query.description = ""
                      	query.order = "CLIENT+DATE"
                      	query.filter = "CLIENT = "+quote(cvar)+" .AND. INVOICE_AMOUNT1-CHECK1-CHECK2-CHECK3-CHECK4>0"
                      	query.options = "I"
                      	tbl.query_create()
                      	'the a_tbl pointer now only sees the records queried
                      	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 = "client"
                      	export.field2 = "date"
                      	export.field3 = "invoice_number1"
                      	export.field4 = "invoice_amount1"
                      	export.field5 = "date6"
                      	export.field6 = "invoice_number2"
                      	export.field7 = "invoice_amount2"
                      	export.field8 = "check5"
                      	a_tbl.export()
                      	'we've exported the records so now close the exporting source instance
                          a_tbl.close()
                          'in the original instance of the table,skip over any more records with the same client id 
                      	while tbl.client = cvar .and. .not. tbl.fetch_eof()
                      	tbl.fetch_Next()
                      	end while
                      	'we're now at the next unique client id, when we get back to the top of this while loop
                      	'the cvar = tbl.client will capture the client id and use that for the next export
                      	'etcetera
                      END WHILE
                      tbl.batch_end()
                      tbl.close()
                      Last edited by Stan Mathews; 01-27-2015, 07:55 PM.
                      There can be only one.

                      Comment


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

                        Thank you Stan. It's just force of habit for me to make surei reference the table with the field. I'll tuck your advice away for future reference. Thanks.....

                        Comment


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

                          When you switch over to V11 we can tidy things up a bit.

                          Code:
                          dim a_tbl as P
                          dim cvar as C
                          'get a crlf() delimited list of one instance each of the client field in client order
                          client_list = table.external_record_content_get("New_Invoicing","alltrim(client)","client",".T. .and. unique_key_value()")
                          'process the list, one entry at a time
                          for each entry in client_list
                          	'the entry variable .value property holds the client "id"
                          	cvar = entry.value
                          	'open the New_Invoicing table for exporting
                          	a_tbl = table.open("New_Invoicing")
                          	'set options and query for the client id obtained above
                          	query.description = ""
                          	query.order = "CLIENT+DATE"
                          	query.filter = "CLIENT = "+quote(cvar)+" .AND. INVOICE_AMOUNT1-CHECK1-CHECK2-CHECK3-CHECK4>0"
                          	query.options = "I"
                          	tbl.query_create()
                          	'the a_tbl pointer now only sees the records queried
                          	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 = "client"
                          	export.field2 = "date"
                          	export.field3 = "invoice_number1"
                          	export.field4 = "invoice_amount1"
                          	export.field5 = "date6"
                          	export.field6 = "invoice_number2"
                          	export.field7 = "invoice_amount2"
                          	export.field8 = "check5"
                          	a_tbl.export()
                          	'we've exported the records so now close the exporting source
                          	a_tbl.close()
                          next
                          There can be only one.

                          Comment


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

                            Hi Stan, I tried the "commented" code for v5 but it's still giving me only one export file, named with the first record that satisfies the criteria, but in that file, all records in the table are showing up, as if it's not seeing the query criteria. I put in a "debug" just prior to the running of the query to follow what it's doing and it goes through the query ok then goes through the export and through the next couple of code lines but when it gets to "tbl.fetch_next()" it goes from there to "end while", back up to "tbl.fetch_next()", back down to "end while" and then onto the final "end while" and then to "tbl.batch_end()", "tbl.close()" and then stops. It obviously has finished, but it is not fetching through the queried records over and over through all of the queried "client" results. Hope this makes sense to you as far as what it is doing.

                            Comment


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

                              I understand what you're saying but not why it would be doing that.

                              As you step through in the debugger, the code should execute as you outlined until it gets to the final end while. Then it should jump back to the top and hit

                              'read the client id of the current record and store that to the cvar variable
                              cvar = tbl.client

                              and start over.

                              That is unless there is only one client and the end of file is fetched.

                              Run it with the debug() in place and when the debugger appears in the bottom section of the debugger window where you see the expression and value boxes, type cvar in the top expression box. Arrow down to the second expression box and type in tbl.client.

                              Step through the script and you should see the variable's value appear and the value in the current tbl.client field appear as the records are processed. The first value appearing in each should be the "smallest" client and it should increase as the records process. Maybe you'll see something I'm not.
                              There can be only one.

                              Comment


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

                                If your client field is numeric you need (no quote())

                                query.filter = "CLIENT = "+cvar+" .AND. INVOICE_AMOUNT1-CHECK1-CHECK2-CHECK3-CHECK4>0"
                                There can be only one.

                                Comment

                                Working...
                                X