Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • putexcel not replacing worksheet with an existing image

    Hello!

    First time poster. I read the Advice on Posting, have looked through Stata manuals, and looked for previous posts and other sites covering this issue. I have not found any materials related to this issue. Apologies if I missed a convention, protocol, or best practice in this post.

    I am running Stata 17 MP. Using putexcel set and specifying the options sheet("Name", replace) modify, if I place an image file into a cell and place a second image in the same worksheet and file, the images stack on top of each other in Excel. The worksheet is not being replaced. Rather, the worksheet is being modified and added to.

    Code:
    sysuse auto, clear
    
    twoway scatter price mpg
    graph export ".\test.png", as(png) replace
    graph close
    
    putexcel set ".\test.xlsx", sheet("Test", replace) modify
    putexcel A1 = image(".\test.png")
    putexcel save
    putexcel close
    erase ".\test.png"
    
    twoway scatter price mpg
    graph export ".\test2.png", as(png) replace
    graph close
    
    putexcel set ".\test.xlsx", sheet("Test", replace) modify
    putexcel A1 = image(".\test2.png")
    putexcel save
    putexcel close
    erase ".\test2.png"
    
    putexcel set ".\test.xlsx", sheet("Test", replace) modify
    putexcel A1 = "Test"
    putexcel save
    putexcel close
    This produces a workbook named "test.xlsx" with one worksheet named "Test". The "Test" worksheet contains two images stacked on top of each other (i.e., clicking and dragging one image reveals a second image) as well as the text "Test" in cell A1. To me, this suggests that the sheet("Test", replace) modify options are not working as intended. However, I want to check with the community here and see if this is a known issue, if my understanding of the putexcel set options sheet("Name", replace) modify is wrong, if my code or syntax are incorrect, or if this is an issue specific to me. I can replicate this issue on other machines in my organization.

    Any help would be appreciated, and I am happy to provide more information if necessary. Thanks!
    Last edited by Brian Wojcik; 27 Aug 2024, 13:28. Reason: Added putexcel tag.

  • #2
    I can confirm that I get the same results as you, running StataNow/MP 18.5 for Windows (64-bit x86-64).

    I hardly ever use -putexcel- myself, so I'm reluctant to affirm that there is not something wrong with this code or your understanding of the -replace- suboption. But it does look correct to me. If nobody else points out a problem in this thread by the end of the day, I suggest contacting Stata technical support about this.

    Comment


    • #3
      Clyde Schechter Thanks for the response, much appreciated.

      Comment

      Working...
      X