Announcement

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

  • putexcel - change the sheet whithout saving the excel file

    Hello,

    I have to write a lot of things into an existing Excel-file with many sheets.

    Example:

    putexcel file.xlsx, sheet("A") modify
    putexcel A1=matrix(A) ...
    putexcel file.xlsx, sheet("B") modify
    putexcel A1=matrix(B) ...
    ...
    putexcel file.xlsx, sheet("Z") modify
    putexcel A1=matrix(Z) ...


    Every time the sheet changes, the file is saved to hd. I tried to keep the file open with

    putexcel file.xlsx, sheet("A") modify open

    but this gave the error "Excel file open" at the next putexcel set ...

    Is there a way to write to different sheets whithout saving the file?

  • #2
    What you need is the open option on the putexcel set command.
    Code:
    . putexcel set results, replace
    Note: file will be replaced when the first putexcel command is issued
    
    . putexcel A1 = "Variable"
    file results.xlsx saved
    
    . putexcel B1 = "Mean"
    file results.xlsx saved
    
    . putexcel C1 = "Std. Dev."
    file results.xlsx saved
    
    . putexcel close
    
    . 
    . putexcel set results, replace open
    Note: file will be replaced when putexcel close command is issued
    
    . putexcel A1 = "Variable"
    
    . putexcel B1 = "Mean"
    
    . putexcel C1 = "Std. Dev."
    
    . putexcel close
    file results.xlsx saved

    Comment


    • #3
      I'm afraid, that won't solve the problem. As I wrote, I have to change the sheet and therefore have to make a new putexcel set file, sheet(...). But at this point I get the error, that the file ist still open!

      Comment


      • #4
        Problem solved. I use mata xl().

        Comment

        Working...
        X