So I want to add a button in my text area in Spotfire which will open an excel file (that is connected to my spotfire visualisation) or at least to a network folder with that file.
I believe I can write an ironpython script just to open that file and make changes. How will I do that?
Update:
After some googling I have tried to run a simple script smth like:
t=open('D:/data/folderA/folderB/file.xlsx','w')
To avoid problems with "/" or "\", I also tried importing os
import os
t=open('D:','data', 'folderA', 'folderB', 'file.xlsx', 'w')
Neither of these work.
For those who is still struggling to find the solution, it turned out to be simpler than I thought it would.
from System.Diagnostics import Process
Process.Start(r 'start c:\test\abc.xlsx')
Related
I have a .exe program that is converting an AGS file to an Excel file.
I have a lot of files to convert so I'm wondering can I automate this with Python? The convert-program only requires 2 locations, one for the input and one for the output, see the picture.
With Python I'm albe to start the program with the following code, but is it possible to pass the 2 path's and click Export.
import subprocess
path = r'C:\Program Files (x86)\AGSToExcel.exe'
#Start the programs
subprocess.call([path])
#other locations
path_ags = r'C:\Users\X\Documents\AGS_file1.ags'
path_excel = r'C:\Users\X\Documents\Book1.xls'
I'm fairly new with package subprocess so I have not a clue if this is even possible.
You can probably use pyautogui to click and type if needed.
You can see a simple example here.
PyAutoGUI EXAMPLE
This title is a bit confusing but let me explain. So say you have a file called test.txt. If you right click on it, it will most likely have a menu appear and will say stuff like "Open in Notepad". How can I get a python file to show in that menu so that it could say "Open in program.py" and the program would run and for example
print(data)
input()
Data being the contents of test.txt. Does anyone know if this is possible?
You need to edit the registry entries in Windows. See this to how.
You have to replace the path with your own script such as C:\\Program Files\\Something\\YourPythonScript %1
%1 represents the associated file name.
Edit: In your python script, you can use sys.argv in order to retrieve the file name of the associated file and process on it.
import sys
#Get selected file
filename = sys.argv[1]
you can use other programs to open your foo.py python code. but that program can't execute the code directly just by one click right. you have to open in program that can run python codes and run the code there.
hope this help you.
In older versions of SPSS, one could ask for the path to a file using a syntax similar to this:
filename = GetFilePath("*.txt","txt", ,"Specify input file",0)
How can I achieve the same result using recent versions of SPSS, that rely on Python?
I found the answer. So similarly to how the VBA in .SBS script works, Python can use a library directly from SPSS to show a file input dialog.
BEGIN PROGRAM.
from Tkinter import Tk
from tkFileDialog import askopenfilename
Tk().withdraw()
filename = askopenfilename()
print(filename)
END PROGRAM.
sbs/wwd scripts are still supported on Statistics.
As for the prompt, you could create a wwd/sbs dialog to prompt for the file name and then open it, or, without using scripting, you could create a custom dialog box using the Custom Dialog Builder (on Utilities) containing a Browse control and issue a GET command.
If you want this to happen when Statistics is launched, you can create a startup script or use the STATS PROJECT extension command, depending on exactly what you want to do.
I am not aware of SPSS Statistics ever having a function such as GetFilePath, but you can use the Python spssaux.getDatasetInfo function for this, e.g., in a program write
import spssaux
filename = spssaux.getDatasetInfo()
I am attempting to open an XML file with Adobe Captivate in my script using os.system(). Here is my code:
os.system("open /Applications/Adobe\ Captivate\ 9/Adobe\ Captivate.app/ \"flashcards_template_changed.xml\"")
It works fine the issue is with the opening screen on Adobe Captivate. When the program is run one of those 'New Document' windows pops up and asks you whether you want to start a new document, what kind of document, etc. Similar to Microsoft Word.
I was wondering if anyone had any experience bypassing this menu so the file would open. When I open Adobe Captivate and open my XML file it opens perfectly so I know it is in the right format.
Any help would be great! Thanks!
If Adobe Captivate is registered as the default application for handling XML files, then you can leave out the application name altogether:
os.system("open flashcards_template_changed.xml")
Otherwise, specify the application with the -a flag:
os.system("open -a captivate flashcards_template_changed.xml")
I don't know for certain that "captivate" is a recognized name for Adobe Captivate; I'm just guessing, and I don't have access to a suitable Mac to find out. If that doesn't work, you could probably use something very similar to what you had in your post:
os.system("open -a '/Applications/Adobe Captivate 9/Adobe Captivate.app' flashcards_template_changed.xml")
I'm writing a script that saves an image file to the desktop (so "image.JPG"). After doing that, I want to open the image file so that it is displayed on the screen. I've been trying to use subprocess (which I have no experience with), but can't seem to get it to work.
import subprocess
subprocess.Popen("C:/Users/first.last/Desktop/image.JPG")
However, that results in the following error:
[error] OSError ( Cannot run program "C:/Users/sean.sheehan/Desktop/image.JPG" (in directory "C:\SikuliX"): CreateProcess error=193, %1 is not a valid Win32 application )
I'm assuming this is because it is a file rather than an application (maybe I have to open an application that allows you to view an image?)
So, is there a way to open an image file in sikuli/jython/python without having to double click it with sikuli? I'd also prefer not to download any additional packages.
Thanks.
If it was a normal Python, you would use os.startfile():
Start a file with its associated application.
import os
filename = "C:/Users/first.last/Desktop/image.JPG"
os.startfile(filename)
But, the problem is that the are things (C-based functionality) that exist in Python, but are missing in Jython. And os.startfile() is one of these things.
subprocess.call() should work in Jython:
import subprocess
filename = "C:/Users/first.last/Desktop/image.JPG"
subprocess.call('start ' + filename)
Also see more options at:
Open document with default application in Python