Open an existing PowerPoint Presentation from a directory
Example from here: Charts from Excel to PowerPoint with Python
My situation is different - the link showed how to to open a new presentation not a saved existing one.
error message:
module None.
You can call out to the open cmd and pass the filename to be opened as the only parameter. It will query the registry to find the program that should be used as default to open such a file, how to do it, and then do it.
This should work, did not check though
subprocess.run(['open', 'the file to be opened.pptx'])
Update: There is also https://docs.python.org/3/library/os.html#os.startfile
Related
I can get python to open an excel file and then save that same excel file, but that’s causing issues when I merge cells and then try to run the program again. I could resolve this issue if I can open the same excel template via python every time and then when the program is finished, it will save that excel file as a user defined name within the same folder the template was opened from. I know there is a saveAs function but I can’t find enough information to be able to get it to work. Thank you!
I have a python app and I'm using xlwings to write to an Excel file. I am trying to create a link to another file. For now, I am trying to link to an Excel file. I am using the code:
ws.range(15, 8).value = '=HYPERLINK("C:\\file.xlsx")'
This creates a link but when I click the link I get the error "cannot open the specified file". The cell value is =HYPERLINK("C:\file.xlsx"). If I create a link to the same file using the "Insert Link" button in Excel it works and both cells show the same file path. Also I will need to create a link to a non-excel file that needs to be opened with a different program. How can I do this?
You should use the add_hyperlink method.
Example:
ws.range(15, 8).add_hyperlink("C:\\file.xlsx")
You need to specify a protocol - specifically, file.
Changing your link to file:///C:/file.xlxs would likely solve your problem. Non excel files would be opened with the default program for that file type (e.g. .txt would open notepad)
I use Jupyter Notebook with Python. I'm not a programmer but I've been learning Python for about a year now.
I was working with some text file that I saved on the same folder of my notebooks, and I accidentally opened a .ipynb file and altered it.
As far as I can tell, I just pasted a text string. I know what I pasted, and I erased it, but now jupyter notebook can't recognize the file. Message is:
Unreadable Notebook: C:\Users\untal\Python\notas analyser.ipynb
NotJSONError('Notebook does not appear to be JSON: \'\\ufeff{\\n "cells": [\\n {\\n "cell_typ...',)
I'm not even close to be able to understand the text file to look for the problem and fix it... I don't even know if that's an option.
Is there any tool or method I can use to recover my notebook?
A possible way to recover corrupted Jupyter notebook files, whether it contains text or not (size = 0KB), is to go to the project folder and display the hidden files.
Once the hidden files are displayed if you are lucky you will see a folder named '.ipynb_checkpoints'.
Open this folder and you should find your notebook.
Using Pycharm worked for me. I wasn't able to actually fix the file, so I had to copy one by one each of the original file's cells to a functional file that I created in python and then opened with Pycharm... After each cell copied, I opened the file with Jupyter to check and fix any problems (going back to Pycharm). Pretty sure is not an optimal solution, but I could save all of my work, so it was an effective solution that can be used by begginers!
The .ipynb file is a JSON file you can try to correct its syntax in online JSON editors. There are many if you look on google. (for example: https://jsoneditoronline.org/#)
Once you have a working JSON file run this text on another notebook to print the cells code.
import json
with open('./1-day.txt', 'r') as f:
data = json.load(f)
for cell in data['cells']:
if 'source' in cell:
[print(i, end='') for i in cell['source'] ]
print('\n#')
I tried the following code to be able to read an excel file from my personal computer.
import xlrd
book = xlrd.open_workbook('C:\\Users\eline\Documents\***\***\Python', 'Example 1.xlsx')
But I am getting the error 'Permission denied'. I am using windows and if I look at the properties of the directory and look at the 'Security' tab I have three groups/users and all three have permissions for all the authorities, except for the last option which is called 'special authorities' (as far as I know I do not need this authority to read the excel file in Python).
I have no idea how to fix this error. Furthermore, I do not have the Excel file open on my computer when running the simulation.
I really hope someone can help me to fix this error.
Sometimes, it is because you try to read the Excel file while it is opened. Close the file in Excel and you are good to go.
book = xlrd.open_workbook('C:\\Users\eline\Documents\***\***\Python', 'Example 1.xlsx')
You cannot give path like this to xlrd. path need to be single string.
If you insist you can use os module
import os
book = xlrd.open_workbook(os.path.join('C:\\Users\eline\Documents\***\***\Python', 'Example 1.xlsx'))
[Errno13] permission denied in your case is happening because you want to read folder like a file which is not allowed.
I ran into this situation also while reading an Excel file into a data frame. To me it appears that it is a Python and/or Excel bug which we should probably not hide by using os.path.join even if that solves the problem. My situation involved an excel spreadsheet that links cells to another CSV file. If this excel file is freshly opened and open when I try to read it in python, it fails.
Python reads it correctly if I do an unnecessary save of the open Excel file.
I'm learning python still, and I want to open a file...I found os.startfile, but this creates a new window every time I want to open a file. How do I hide this window?
I'm sure there is another way instead of os.startfile that actually does this...any ideas?
Also, I'm trying to download one of the attachments in this weird format, any ideas? The file is originally a msg file.
Thanks! :D