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

Export to Excel Tabs?

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

  • DORaymond
    replied
    Re: Export to Excel Tabs?

    Mike - thanks for your reply. I worked out what I wanted to accomplish using bits of the code on this thread and some internet searching. I have an app where I needed one records worth of data at a time to be injected into different excel sheets.

    HTML Code:
    	Dim templatex AS C
    	Dim cutsheetx AS C 
    	Dim xlApp as p
    	dim myCell as c
    	
    	
    	templatex = "P:/Donald/" +alltrim(var->Template)+ ".xlsx" 'This is the template file to use                                                        
    	cutsheetx = "P:/Donald/" +alltrim(str(var->Cutsheetkey))+ ".xlsx" 'This is the name of the file that is created/saved
    	
    	if file.exists(cutsheetx) then
    	    templatex = cutsheetx
    	    
    	 else
    	 	templatex = templatex
    	end if
    	
    	xlApp = ole.create("Excel.Application")
    	xlApp.Workbooks.Open(templatex)
    	xlApp.sheets("Sheet2").Select()
    	'xlApp.Visible = .T. 'comment this line out if you don't want to see Excel
    	tbl = table.open("cutsheet")
    	query.filter = "Cutsheetkey = var->cutsheetkey"
    	query.order = "recno()"
    	query.options = "N"
    	query.description = "Temporary Query"
    	ix = tbl.query_create()
    	recs = ix.records_get()
    
    	
    	
    		xlApp.Range("B3").Select()
    		xlApp.ActiveCell.Formula = alltrim(tbl.Unit_Label)
    		xlApp.Range("B4").Select()
    		xlApp.ActiveCell.Formula = alltrim(tbl.Str_Type)
    		xlApp.Range("B5").Select()
    		xlApp.ActiveCell.Formula = alltrim(tbl.Insidedim)
    		xlApp.Range("B6").Select()
    		xlApp.ActiveCell.Formula = alltrim(str(tbl.Topofwall))
    		
    		query.filter = ""
    			
            tbl.close()
    	xlApp.Columns("B").Autofit()
    	xlApp.Range("A1").Select()
    	xlApp.sheets("Sheet1").Select()
    	xlApp.Range("A1").Select()
    	xlapp.DisplayAlerts = .F.
    	xlApp.ActiveWorkbook.SaveAs(cutsheetx) '-4143 is latest supported version,-4143
    	xlApp.Workbooks.Close()
    	xlapp.DisplayAlerts = .T.
    	xlApp.Quit()
    	
    	sys_open("P:/Donald/" +alltrim(str(var->Cutsheetkey))+ ".xlsx")

    Leave a comment:


  • Mike Wilson
    replied
    Re: Export to Excel Tabs?

    Hi Don,
    When you say that you need to "integrate" Alpha with Excel, can you explain what that means more specifically? The application I developed and manage now has so many interfaces with Excel that I wonder what your definition of "integrate" is.

    Leave a comment:


  • DORaymond
    replied
    Re: Export to Excel Tabs?

    Stan - This is an old post, but I have a project where I need to integrate Alpha with Excel. Do you know where I can find documentation where I can learn more about the code you have used in this thread?

    Thanks - Don

    Leave a comment:


  • Al Buchholz
    replied
    Re: Export to Excel Tabs?

    Originally posted by Keith Hubert View Post
    Thanks Guys.

    You are just tooo much.
    Hey, I resemble that remark... ;)

    Leave a comment:


  • Keith Hubert
    replied
    Re: Export to Excel Tabs?

    Thanks Guys.

    You are just tooo much.

    Leave a comment:


  • Al Buchholz
    replied
    Re: Export to Excel Tabs?

    Originally posted by Keith Hubert View Post
    Hi Stan,

    Sorry, did not explain properly.

    What I had in mind was loading data from another table into the same spreadsheet but on another named tab.

    The other aspect is, how do I control the path to see the spreadsheet in the My Documents folder?
    Keith

    Using the Alpha DAO export, I export multiple tables to a single spreadsheet with each table in it's own tab.

    I can control what field go into a column.

    Stan's method is fantastic if you need to have individual cell control, but requires a bit more work - as expected.

    Leave a comment:


  • Stan Mathews
    replied
    Re: Export to Excel Tabs?

    I believe the normal location of My Dcouments is in the pattern

    C:\Documents and Settings\smathews\My Documents

    So you have to know the user name and concatenate.

    Code:
    user = "smathews"
    
    ? "C:\Documents and Settings\\"+user+"\My Documents"
    = "C:\Documents and Settings\smathews\My Documents"
    loading data from another table into the same spreadsheet but on another named tab.
    You select the other tab as described and open the other table.

    From your code export_sales2, just add another section.


    Code:
    FUNCTION export_sales2 AS L (excelname AS C, newname AS C )
    export_sales2 = .F.
    Dim xlApp as p
    dim myCell as c
    xlApp = ole.create("Excel.Application")
    xlApp.Workbooks.Open("keith_sheet")
    XlApp.Sheets("Tab 1").Select()
    xlApp.Visible = .T. 'comment this line out if you don't want to see Excel
    tbl = table.open("new_sales")
    query.filter = ".T."
    query.order = "recno()"
    query.options = "I"
    query.description = "Temporary Query"
    ix = tbl.query_create()
    recs = ix.records_get()
    tbl.fetch_first()
    start_cell = 9
    FOR t = 0 TO recs
    xlApp.Range("A"+alltrim(str(start_cell+t))).Select()
    xlApp.ActiveCell.Formula = alltrim(tbl.sales_rep)
    xlApp.Range("B"+alltrim(str(start_cell+t))).Select()
    xlApp.ActiveCell.Formula = tbl.Total_Invoice_Items__Extension
    'xlApp.Range("C"+alltrim(str(start_cell+t))).Select()
    'xlApp.ActiveCell.Formula = alltrim(tbl.email)
    tbl.fetch_next()
    NEXT t
    tbl.close()
    xlApp.Columns("A:B").Autofit()
    xlApp.Range("A1").Select()
    XlApp.Sheets("Tab 2").Select()
    xlApp.Visible = .T. 'comment this line out if you don't want to see Excel
    tbl = table.open("some_other_table")
    query.filter = ".T."
    query.order = "recno()"
    query.options = "I"
    query.description = "Temporary Query"
    ix = tbl.query_create()
    recs = ix.records_get()
    tbl.fetch_first()
    start_cell = 9
    FOR t = 0 TO recs
    xlApp.Range("A"+alltrim(str(start_cell+t))).Select()
    xlApp.ActiveCell.Formula = alltrim(tbl.sales_rep)
    xlApp.Range("B"+alltrim(str(start_cell+t))).Select()
    xlApp.ActiveCell.Formula = tbl.Total_Invoice_Items__Extension
    'xlApp.Range("C"+alltrim(str(start_cell+t))).Select()
    'xlApp.ActiveCell.Formula = alltrim(tbl.email)
    tbl.fetch_next()
    NEXT t
    tbl.close()
    xlApp.Columns("A:B").Autofit()
    xlApp.Range("A1").Select()
    xlapp.DisplayAlerts = .F.
    xlApp.ActiveWorkbook.SaveAs(newname,-4143) '-4143 is latest supported version
    xlApp.Workbooks.Close()
    xlapp.DisplayAlerts = .T.
    xlApp.Quit()
    ex_keith = .T.
    END FUNCTION

    Leave a comment:


  • Keith Hubert
    replied
    Re: Export to Excel Tabs?

    Hi Stan,

    Sorry, did not explain properly.

    What I had in mind was loading data from another table into the same spreadsheet but on another named tab.

    The other aspect is, how do I control the path to see the spreadsheet in the My Documents folder?

    Leave a comment:


  • Stan Mathews
    replied
    Re: Export to Excel Tabs?

    Not sure I understand the question fully

    If you want to address a specific sheet you use

    XlApp.Sheets("sheetname").Select() 'note quotes

    or

    XlApp.Sheets(sheetnumber).Select()

    If you want to put the same data

    (a) but on a different tab

    you repeat the code section and change the sheet number or name. You could also create a list of sheet numbers or names and feed them to a

    for each..

    next
    loop

    For (b) different data onto a different tab you change sheetnumbers or names and have a different set of data insertion instructions.

    Leave a comment:


  • Keith Hubert
    replied
    Re: Export to Excel Tabs?

    Hi Stan,

    Back to this again.

    OK, I can enter data into a selected tab, the next question is what is the best method to use to enter data into the same spreadsheet (a) but on a different tab and (b) different data onto a different tab?

    Leave a comment:


  • Stan Mathews
    replied
    Re: Export to Excel Tabs?

    If they're not going to give you the password there's not much we can do. If they give you the password then you can unprotect it manually and save it. Then operate on the unprotected version.

    Leave a comment:


  • Keith Hubert
    replied
    Re: Export to Excel Tabs?

    Hi Stan,

    Yes you are correct, Excel does stop and ask for a password.

    The spreadsheet I'm trying to export to is not mine, which means I dont have full access to it.

    Leave a comment:


  • Stan Mathews
    replied
    Re: Export to Excel Tabs?

    The reason I asked about the protection is that the command to unprotect the sheet, in xbasic, is simply

    xlApp.ActiveSheet.Unprotect()

    I don't see a way to supply the password, if there is one, to the command.

    Leave a comment:


  • Stan Mathews
    replied
    Re: Export to Excel Tabs?

    Try changing the xlapp = ole.create() to

    xlApp = ole.getobject("","Excel.Application")

    The OLE.GETOBJECT() method uses an existing OLE automation object, if available. Otherwise, it creates a new one.

    Leave a comment:


  • Keith Hubert
    replied
    Re: Export to Excel Tabs?

    Hi Stan,

    Thanks for getting back so quickly.

    Unfortunately the FOR t = 0 TO recs - 1 did not make nay difference, I still get the last record duplicated.

    As I was writing this I changed the start_cell to start_cell = 8 and that has eliminated the duplication.

    If I remove the .Autofit() I no longer get the error message but I have to make sure Excel is not open first. I need to experiment to see what happens when I try to add data to another tab on the same spreadsheet.

    Leave a comment:

Working...
X