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

Formatting Excel or CSV

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

    Formatting Excel or CSV

    I have a header and detail record set. The Detail is in a browse which is marked as paid which I want to export.

    Customer
    ..Invoice 1
    ..Invoice 2
    ..Invoice N

    What is the best way to present this in a CSV or Excel format?

    The CSV shows the Customer name against each invoice, and I need just the one line followed by the invoice details, viz;
    Aardvark Enterprises Ltd
    Invoice 1
    Invoice 2
    Invoice n

    and not
    Aardvark Enterprises Ltd, Invoice 1
    Aardvark Enterprises Ltd, Invoice 2
    Aardvark Enterprises Ltd, Invoice n

    The Excel output won't show the data from the browse, or at least I cannot get it to do so.

    Using a Form and exporting to Excel is a possibility but I am attempting to reduce the user effort and mouse clicks.

    Preferred option is the CSV route.

    Any ideas?
    See our Hybrid Option here;
    https://hybridapps.example-software.com/


    Apologies to anyone I haven't managed to upset yet.
    You are held in a queue and I will get to you soon.

    #2
    Re: Formatting Excel or CSV

    For a set where the detail you want in the csv files consists of parent and a single child fields, current record visible on the form.

    Code:
    tbl_prnt = table.current(1)
    tbl_chld = table.current(2)
    
    filnam = ui_get_file("Name for export","*.csv","C:\temp\exported.csv","N")
    if filnam <> ""
    	fil = file.create(filnam,FILE_RW_EXCLUSIVE)
    	fil.write_line(tbl_prnt.[COLOR="#FF0000"]customer_name_field[/COLOR])
    	tbl_chld.fetch_first()
    	while .not. tbl_chld.fetch_eof()
    		fil.write_line(tbl_chld.character_field+" "+alltrim(str(tbl_chld.numeric_field1,10,2))+"  "+alltrim(str(tbl_chld.numeric_field2,10,2))) 'modify this line to construct child details desired
    		tbl_chld.fetch_next()		
    	end while
    	fil.flush()
    	fil.close()	
    else
    	msgbox("No filename supplied.")
    end if
    Last edited by Stan Mathews; 06-27-2018, 10:38 AM.
    There can be only one.

    Comment


      #3
      Re: Formatting Excel or CSV

      Thanks Stan.
      I will try this later when I get on the Desktop.
      Will this print only the child records visible in the browse?
      The invoice records may not all be marked as paid, so I have a P for paid in the child table, and show only those with P in the browse when printing to CSV at present. Only those in the browse print.
      See our Hybrid Option here;
      https://hybridapps.example-software.com/


      Apologies to anyone I haven't managed to upset yet.
      You are held in a queue and I will get to you soon.

      Comment


        #4
        Re: Formatting Excel or CSV

        The code should copy only those records available to the form at the time it is executed. The current parent and linked child records. I am unclear on how you "show only those with P in the browse". If you have queried the form/set for P in the browse it will also limit the records available to the code.
        There can be only one.

        Comment


          #5
          Re: Formatting Excel or CSV

          Thanks, in front of the DT now so will get on and implement.
          It works like a dream!

          The Show only those with P is run from a button launching a coded query.

          At the risk of trying your infinite patience, can I copy the field names as well, viz;

          Customer
          Invoice Number, Invoice Date, Invoice amount (or a text line under Customer?)
          12345 01/01/1900 $1234.00
          23456 02/03/1901 $ 234.00

          or would I be better inserting a text line to match the content (as commented above)?
          See our Hybrid Option here;
          https://hybridapps.example-software.com/


          Apologies to anyone I haven't managed to upset yet.
          You are held in a queue and I will get to you soon.

          Comment


            #6
            Re: Formatting Excel or CSV

            I think you are better off just adding a line of text as you have to know the field name to use a method that returns the field name.
            tbl_chld.fieldname.name_get() seems unnecessarily obscure.

            Using a text line you can also format as you want. If the field is really "inv_num" and you want "Invoice Number" in the csv just adding the text is better.

            fil = file.create(filnam,FILE_RW_EXCLUSIVE)
            fil.write_line(tbl_prnt.customer_name_field)
            fil.write_line("Invoice Number, Invoice Date, Invoice amount")
            ' rest of script

            This illustrates a point which is not obvious and took me some time to fully understand.

            When you obtain a table.current(#) pointer to the table(s) of an open form, you are by definition limited to the records visible on the form. If you are performing some processing on those records you will likely want to use the <tbl>.get_cursor() method instead but if you just want to gather information you can fetch, loop, whatever, without worrying about accidentally navigating to unrelated child records.
            Last edited by Stan Mathews; 06-27-2018, 01:01 PM.
            There can be only one.

            Comment


              #7
              Re: Formatting Excel or CSV

              I am indebted Stan, many thanks for the leg up.
              See our Hybrid Option here;
              https://hybridapps.example-software.com/


              Apologies to anyone I haven't managed to upset yet.
              You are held in a queue and I will get to you soon.

              Comment


                #8
                Re: Formatting Excel or CSV

                All sorts of fun things you can do.

                Code:
                tbl_prnt = table.current(1)
                tbl_chld = table.current(2)
                
                filnam = ui_get_file("Name for export","*.csv","C:\temp\exported.csv","N")
                if filnam <> ""
                	ctr = 0
                	ttl1 = 0
                	fil = file.create(filnam,FILE_RW_EXCLUSIVE)
                	fil.write_line(tbl_prnt.[COLOR="#FF0000"][/COLOR][COLOR="#FF0000"]customer_name_field[/COLOR])
                	fil.write_line("Invoice Number, Invoice Date, Invoice amount")
                	tbl_chld.fetch_first()
                	while .not. tbl_chld.fetch_eof()
                		fil.write_line(tbl_chld.[COLOR="#FF0000"]invoice_number[/COLOR]+" "+dtoc(tbl_chld.[COLOR="#FF0000"]invoice_date[/COLOR],"1-")+"  "+alltrim(str(tbl_chld.[COLOR="#FF0000"]invoice_amount[/COLOR],10,2))) 'modify this line to construct child details desired
                		ctr = ctr + 1
                		ttl1 = ttl1+tbl_chld.[COLOR="#FF0000"]invoice_amount[/COLOR]
                		tbl_chld.fetch_next()
                	end while
                	fil.write_line("") 'blank line for spacing
                	fil.write_line("Processed "+alltrim(str(ctr)) +" records.")
                	fil.write_line("Invoice amount total is "+alltrim(str(ttl1,10,2)))
                	fil.flush()
                	fil.close()
                else
                	msgbox("No filename supplied.")
                end if
                Adjust test field names to fit your actual names.
                There can be only one.

                Comment


                  #9
                  Re: Formatting Excel or CSV

                  Thanks again.
                  As you know, I avoid code wherever possiible.
                  I try to adhere to the Alpha concept of no/low code.
                  Alpha is sooooo flexible, that it gets you imagination whirring, and before you know it, code is required cos just mouse clicks don't quite cut it.
                  I am my own worse enemy.
                  See our Hybrid Option here;
                  https://hybridapps.example-software.com/


                  Apologies to anyone I haven't managed to upset yet.
                  You are held in a queue and I will get to you soon.

                  Comment


                    #10
                    Re: Formatting Excel or CSV

                    I am my own worse enemy.
                    been there
                    Robin

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

                    Comment

                    Working...
                    X