Announcement

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

  • How to save to a xls file (in place of the csv original file) and then close shellout window results?

    Dear Statalist members:
    Can anyone help me with this task. I cannot find the appropiate way to do this with winexec or shell commands.
    I have a csv file. I want to open it from Stata using shellout (or winexec, or shell), save it as a xls file and finally close microsoft excel.
    Thanks in advance
    Demian


  • #2
    Unless Excel accepts some argument from a shell command which makes it save, I very much doubt this is possible.

    The closest thing I can think of is that you could import the csv file to Stata then export it to a xls. Obviously you would lose any formatting and probably some other complexities.

    Comment


    • #3
      Thanks a lot Tom, but I'm trying to avoid the import step because of some import problems which disappear when the csv file is converted to xlsx from outside (Microsoft Excel itself)
      I'm trying with something like this:

      ! "C:\Program Files (x86)\Microsoft Office\Office12\excel.exe" impom17.csv
      ! taskkill /im EXCEL.exe

      It works but -obviously- without changing the file extension...

      I cannot find the way to pass the "save.as" argument.

      It should be something like this

      ! "C:\Program Files (x86)\Microsoft Office\Office12\excel.exe" impom17.csv /e/ActiveWorkbook.SaveAs(impom17.xlsx)

      Unfortunately, it doesn't works


      Comment


      • #4
        Best to find out and solve what the original problem is.

        Otherwise, why not read in the .csv and then export the .xlsx using Stata alone?

        Why open Excel at all? (In fact, why do you need the .xlsx?)

        Comment


        • #5
          Originally posted by Demian Panigo View Post
          I'm trying to avoid the import step because of some import problems which disappear when the csv file is converted to xlsx from outside
          Please describe your problem. Is it related to character encoding? The commands below may be useful.
          Code:
          unicode convertfile
          unicode translate

          Comment


          • #6
            You are right. But I cannot find the very nature of the problem (I think it is related to regional configuration issues)
            I've tried a lot of different alternatives and the only one that works is the Excel-Stata above mentioned procedure.
            Thus, I thought it will be a good excuse to learn something about passing arguments to MS programs from whitin Stata using winexec.
            Anyway, thank you very much.

            Comment


            • #7
              If the problem is related to file encoding, you could see this as an opportunity to learn more about Stata's unicode command. As an example, this post describes a problem that was solved with unicode convertfile.

              You can tell us more about your problem (see section 12 in the FAQ for advice on using Statalist) or you can contact Stata tech support.

              Comment


              • #8
                Thank you very much Huebler

                Comment

                Working...
                X