Opening an Excel (.xlsx) file on system restart and enabling autosave automatically - python

Context:
We have some Excel files with embedded VBA used only for refreshing them (the data source for each one of these Excel files is a SQL query therefore on refresh, the data gets pulled). After refresh, the file gets saved. All of these files are already saved in the One Drive folder.
When you open an Excel file that is stored in the OneDrive folder along with a specific ceremony (you have to first open Excel application, then go to open, then through Excel application open each file separately from the OneDrive folder), the AutoSave gets activated on Excel file. I hear that this is only available in O365.
Problem:
The problem is that on system restarts, planned & unplanned, we have to repeat this.
Granted this is not an efficient system to begin with and you can question the method itself, I was wondering if there is a way to open the files on system restart automatically with AutoSave enabled.
So far:
Please let me know if you need more information.
Currently I have tried Python and batch command, both open the file but do not enable the autosave which makes it pointless since the files should get save to OneDrive. It is worth mentioning that I used gpedit.msc in Run (Windows) to run the batch file on system restart and I have used the path for the shortcut of .bat file. The reason is that I wanted to test and see if running the .bat in Administrative mode would fix this and the only way that you can run a .bat file in admin mode is to create a shortcut and then set the default run-mode of that file to Admin mode.
For Python I used this script:
import os os.chdir('C:\\Users\\USER\\FOLDER) os.system('FILE.xlsx')
For .bat file I used this
#echo off set params=%* start excel "C:\Users\USER\FOLDER\FILE.xlsx" /e/%params%
I have tried using .bat to run Python to open the files as well and that also failed.
Many thanks in advance,

Related

File Permission InstallForge

I have written a Python program, this must change the contents of a file for a function.
This also works so far, but I have now converted this with Auto-py-to-exe into a folder, and also the required file is inserted.
When I open this exe file, everything works!
The problem occurs when I use InstallForge to convert the file to an installer file, transfer the file to another PC, restart the PC, open the software, and then try to use the function that describes a file. The software then crashes and the file is not saved.
If I run the software as admin, it doesn't get the error, so that means yes, to be able to rewrite files in the folder, you need admin permission. But it's just inconvenient to always be able to open the app by right clicking and then using "run as administrator".
Is there any way to simplify this? Can i use InstallForge to set special permissions to the files?
I have try, to search about it in the internet, but i havn't found anything about that.

File not found when running a file in JupiterLab console

Every time when I try to run a file in the JupiterLab console I get the following message:
ERROR:root:File 'thing.py' not found.
In this case, my file is called thing.py and I try to run it with the trivial run thing.py command in the console. The code is running and it gives me correct results when executed in the console, but I wanted to have it saved, so I put it in a JupiterLab text file and changed the extension to .py instead of .txt. But I get the aforementioned message regardless of which file I try to run. I am new to JupiterLab and admit that I might have missed something important. Every help is much appreciated.
If you're running Jupyterlab you should be able:
to create a new file & paste in your commands
Rename that file to "thing.py"
And then open a console in the same Jupyterlab instance and run that file. Notice that you can see "thing.py" in the file explorer on the left:
Alternatively, you can use the %load magic command in a notebook to dynamically load the code into a notebook's cell.
You might want to understand exactly what a Jupyter Lab file is, and what a Jupyter Lab file is not. The Jupyter Notebooks have the extension, .ipynb.
So anyway, the Jupyter Notebooks are not saved or formatted with python extensions. There are no Jupyter Notebooks or Jupyter Labs ending with the .py extension. That means Jupyter will not recognize an extension having .py, or .txt or .R or etc.... Jupyter opens, reads, and saves files having the .ipynb extension.
Jupyter Notebooks are an open document format based on JSON.
Jupyter can export in a number of different formats. Under the File tab, is the Export feature. The last time I looked there were about 20 different export formats. But there isn't a python or .py export format. A Jupyter file can also be Downloaded. Also under the File tab is the Download feature. This will download a standard text formatted JSON file. JSON files are mostly unreadable unless you've spent years coding JSON.
So there's not much purpose in downloading the Jupyter file unless you are working on a remote server and cannot save your work at that site. And it makes much more sense to save and copy the Jupyter file in its native Jupyter format - that means having the extension, .ipynb . Then just open and use that file on another PC.
Hopefully this should clarify why Jupyter won't open any .py or .txt files.

Why can python files be modified while open in IDLE editor?

When a .py file is being edited in IDLE, it can be renamed or deleted while still being able to run, but in other file types such as word files this is not allowed. You can even create a script using the os module to delete itself and then do an action, and that action still works. How is this possible?
When you run python scripts you scripts were loaded into memory. So you can edit your script files.

How to access "locked" files for backup program

I am trying to create a google drive like backup program using python that backs up to a Linux box that will further backup to an off site place tbd. I have ran into a few interesting coding and computer challenges in doing this.
The one I am working on right now has to do with "locked" files. So what do I mean by this? In windows 7 if you create a .txt file you can open it in notepad(any program) and at the same time you can open it in a python program. If you make a change in the .txt file and save the change but BEFORE closing it you can still open and see the changes in pythn. Now change the file to a .docx windows file and open it with word 2007. While opened in word you cannot access it with in python until the user closes it.
Now if you look at google drive, the desktop install not the web only variety, you can open a .docx file and change it. Once you save it but BEFORE closing google drive has already synched the file.
Google drive must have some sort of lower level access to the file than the simple python file.open() command.
So here is the question. Does anyone know of a way to access files in python in such a way as to keep me from having to wait for the user to close the file.
Edit 1:
Let me further explain. Once I have created an sqlite database that has all the files and directories I will then use the win32file.ReadDirectoryChangesW() function to monitor for changes. My problem stems from the fact that when setting up the application of first install/run it must catalog all files and files that are open in windows office are locked and cannot be cataloged. Is there a way around this?
Many backup tools use snapshots. Then, they'll copy the locked file directly from the snapshot rather than coping it directly from the filesystem. If you're on Windows you should check Windows VSS, see the Microsoft documentation for more details. Otherwise, if the filesystem you're on supports snapshots check its documentation as well.
Third party tools
You can use the subprocess Python module to run third-party tools which will take snapshots for you.
Microsoft VSS
In case you want to do it by yourself you might need modules from the Win32 API such as win32com module.
There is also on Github a project that seems to do the job: pyshadowcopy
Filesystem Snapshot
Depending on the filesystem features, you might find python modules or tools allowing you to take a snapshot.

Python files created do not save as python file

https://drive.google.com/file/d/0BwR0ium7uufRWnhXWWNFcVJ3S2c/edit?usp=sharing
The files that are blank and say "Credit Card Balance" and "mine" are the files which I created by opening up a new document in IDLE and creating a file. The ones with the little pictures and say ps2_newton are programs which I downloaded off of the internet. I can't open my files which I created like they are regular programs and have to open them under notepad to see the code. Why is this? How can I change my files to look and act like the ones I downloaded?
The files you downloaded have an extension of ".py", which tells Windows to open them with the Python launcher, while the ones you created have no extension, or an extension of ".txt", which tells Windows to open them in Notepad.
Since ".py" and ".txt" are both "known extensions", and you have Explorer configured to hide known extensions (which I believe is the default in all versions of Windows), it doesn't show them to you. However, you can see the difference in the icons.
You can configure Explorer to show all extensions, but this site is not the place to ask about that—try SuperUser.
Meanwhile, when you save your scripts, make sure you save them with a .py extension (or, if they're Tkinter or other GUI apps, with a .pyw extension).
I had the same problem. But I just deleted all of the é's and á's etc. And it worked! So try that IF it is an .py file. Otherwise I understand if it does not work becouse it isn't a python file. You change that by doing this: Save as. Just simply type .py after the file name.
PS Sorry for my bad english...

Categories

Resources