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

Write to Excel, read results of a formula

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

    Write to Excel, read results of a formula

    All,

    I'm trying to push a value out to an Excel spreadsheet, and then read the results of a formula in another cell that references the pushed value.

    For example:
    A1=5
    A2=5
    A3=10 (A1+A2)

    If I push 30 into A2, and then Read A3 it still contains 10. I'd like it to contain the new total of 35.

    So far, the only way I can find to get the formula to refresh is to actually open the Excel file.

    Does anyone know how to force an attached Excel data source to refresh it's formulas?

    #2
    Re: Write to Excel, read results of a formula

    Can we ask WHY you want to do this?

    Why not do the calculation first, then push the finished product to Excel?

    I assume you have a really complex excel spreadsheet with formulas just the way you like them and your example above is a simplification, but still …

    All I can think of is that you save, close the connection to the excel file, then reopen it. That might trigger a formula refresh.

    Comment


      #3
      Re: Write to Excel, read results of a formula

      I tried this using the Office::ExcelDocument class. I don't see a way to read the current value of a cell calculated with a formula... or to refresh it's contents. Reading the cell seems to be hit and miss. Either I get the original value or I get zero after updating the cells used by the formula.

      How are you getting at the Excel Sheet... what's the code you're using? And what Alpha version/build are you using?

      I've had more luck using OLE, but the doc, as usual, is terrible.

      Comment


        #4
        Re: Write to Excel, read results of a formula

        Larry and David, Thanks for responding.

        First to Larry, you are correct. I have an extremely complex excel spreadsheet that I will be using, and the example if definitely over simplified.

        David, I'll paste me code below and I'm using the latest version I think v4.5.4.8 Build 5581

        Code--------------------------------------------------------------
        dim vFilePath as c = "C:\Temp\Attributes.xlsx"
        dim vResults as n

        dim Doc as Office::ExcelDocument
        dim Sheet as Office::Spreadsheet
        if Doc.Load(vFilePath)
        if Doc.FindSheet(Sheet,"tbl_Attributes")
        Sheet.Write(2,3,500)
        Doc.Save(vFilePath)
        end if
        end if
        delete Doc

        dim Doc as Office::ExcelDocument
        dim Sheet as Office::Spreadsheet
        if Doc.Load(vFilePath)
        if Doc.FindSheet(Sheet,"tbl_Attributes")
        vResults = Sheet.Read(5,3)
        end if
        end if
        delete Doc

        Comment


          #5
          Re: Write to Excel, read results of a formula

          It's been a very long time since I worked with Alpha and Excel. I always found Alpha methods and functions either too difficult to work with... or they were just a bit too flakey.

          Using the Office::ExcelDocument class I can write to cells... but cannot read the value of a formula cell.
          Using OLE, I cannot write to cells, but can read the value of a formula cell.

          I know it's stupid, but combining the class and OLE I can do what you want to accomplish. It's just that it's silly.

          Using the doc for the class... https://documentation.alphasoftware....Operations.xml
          and Using the doc for OLE (which is wrong)... https://documentation.alphasoftware....with%20OLE.xml

          here is code that uses both to write to cells and then read the results from a formula cell...

          Code:
          function excelOLE as c (e as p)
          
          	debug(1)	
          	dim ptr2[1,3] as C
          	get_excel_data("C:\Exceltest\book1.xlsx", 1, 1, ptr2)	
          	
          end function
          
          function get_excel_data as V (Filename as C, First_Row as N, First_Col as N, Data_Array as P)
          	debug(1)
          
          	'using Class code to update a cell
          	dim Doc as Office::ExcelDocument
          	dim filename as C = "C:\Exceltest\book1.xlsx" 
          	dim SheetName as c = "Sheet1"
          	dim Sheet as Office::Spreadsheet
          	
          	if Doc.Load(filename) 
          	    if Doc.FindSheet(Sheet,sheetName) 
          	        Sheet.Write(1, 1, 22) 
          	        Doc.Save(filename) 
          	    end if 
          	end if
          	delete Doc
          	delete Sheet	
          	
          	'now use OLE to read a cell value based on a formula
          	dim ExcelBook1 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
          	ExcelBook1 = ole.getobject(Filename)
              
          	for row = First_Row to First_Row + rows
          		for col = First_Col to First_Col + cols
          			cell = get_col(col) + row
          			Data_Array[row,col] = ExcelBook1.activesheet.Cells.Range(cell)
          		next col
          	next row
          
          quitting:
          
          	ExcelBook1.close()
          	delete ExcelBook1
          
          end function
          
          ' Computes the column letter
          function get_col as C (num as N)
          	dim k as N
          	dim c1 as C
          	dim c2 as C
          	k = int( mod(num/26,26) )
          	c1 = if(k > 0, chr(k + 64), "")
          	c2 = chr(num - (k * 26) + 64)
          	get_col = ltrim(c1+c2)
          end function

          Comment


            #6
            Re: Write to Excel, read results of a formula

            That did it! Thanks for the code. I agree, it's stupid that it needs to be done that way but in the end, I just wanted it to work, and it does.

            Thanks again.

            Comment


              #7
              Re: Write to Excel, read results of a formula

              Originally posted by CampnJim View Post
              That did it! Thanks for the code. I agree, it's stupid that it needs to be done that way but in the end, I just wanted it to work, and it does.

              Thanks again.
              File is just a file. Excel makes data and formulas alive. So nothing stupid here.

              Comment


                #8
                Re: Write to Excel, read results of a formula

                How can I update excel cell values using OLE and not the class? Some of the cells I'm referencing have vba behind them and they're not updating their values like the non-vba ones do. I'm hoping that if I update them after opening the file via OLE the vba cells will update.

                Comment


                  #9
                  Re: Write to Excel, read results of a formula

                  Jim, you'll need to ask Alpha. There's not enough Alpha doc on this for OLE or the Class. Code that seems to make sense doesn't work.

                  Comment

                  Working...
                  X