So, I'm trying to use lowriter to convert some files from doc/docx to pdf inside my program. When I run it like a sub process I get 'Application Error' like below
>>rest = subprocess.getoutput('lowriter --convert-to pdf --outdir ./data/temp_convert "<FILE_PATH>/file.docx"')
>>rest
'Application Error'
But when I run it directly form the terminal everything works fine:
$ lowriter --convert-to pdf --outdir ./data/temp_convert "<FILE_PATH>/file.docx"
convert <FILE_PATH>/file.docx -> ./data/temp_convert/file.pdf using filter : writer_pdf_Export
Any idea what might be causing this?
Ps. This is an old script that worked before last week and I changed nothing since the last working build
Related
I have a Python script (gui.py - a calculation program, written by somebody else). I try to run this from excel with input data from the same excel file. It works fine when I start the script as:
objShell.Run PythonExe & PythonScript3
In the python script I used the following to get f.ex data from H5 cell, works also fine:
import openpyxl
wb = openpyxl.load_workbook("01.xlsm")
ws = wb.active
mastNumber = ws['H5']
But I don't want to edit a lot in gui.py (have just simple changes) so I planned to use a 2nd script (caller.py) which gets the data from Excel, then I import this to gui.py and there I just use the variable from caller.py. It works also as long as I start gui.py directly. When I start it from Excel I get an error msg.
error msg
So as long as the flow is not Excel -> gui-py -> which imports caller to get data from same Excel file -everything works fine.
I am open to any solution for this problem or a completely new approach if there is better for somebody with limited programming skills.
Looking at the error, can you try putting complete path of the excel file at line wb = openpyxl.load_workbook("01.xlsm") instead of just 01.xlsm.
I want to write a tutorial for python (assume basic python) and I want to make a pdf version using latex. I want to run a session of jupyter notebook and write codes step by step and print the steps in pdf.
I want to get something like this:
In [12]: a = 'foo'
In [13]: type(a)
Out[13]: str
When I use magic code %logstart -o myfile.py I get something like this:
2+2
#[Out]# 4
is there anyway to log my codes like first style?
Exporting the notebook as a web page with File > Download as > HTML, will save the contents as they are presented on the screen.
You can then edit and convert that file to tex with the pandoc command-line utility:
pandoc -i notebook.html -o notebook.tex
After you're done editing the file (it's bound to have a few errors unfortunately), you can create a pdf:
pandoc -i notebook.tex -o notebook.pdf
I am trying to add a vba_project to "Sheet1" of a workbook using python.
I am following XLSXWRITER documentation to get the bin of the VBA code from a different sheet which I would want to use in "Sheet1" of my new workbook.
I enter the below code in command prompt but I get the error: "'vba_extract.py' is not recognized as an internal or external command"
$ vba_extract.py Book1.xlsm
Extracted: vbaProject.bin
Can someone give me a step by step on how to extract the macro from old file as bin and then input into sheet1 of new workbook using python?
You have to tell the cmd you're running a python file.
Try this batch code:
cd C:\path\of\yourfile.py
python vba_extract.py Book1.xlsm
edit:
Added cd command, you have to be in the folder of the python file.
I figured this out today and just wanted to leave it here for any future people to use. This was so unbelievably frustrating to figure out how to do. If you are using the Pandas library, this is also relevant. Make sure to install xlsxwriter also.
1.Click on your windows start button and type 'cmd' and click on it to run the Command Prompt.
2.Once you have it open, you need to locate where the vba_extract.py file is. For me it was here:
C:\Users\yourusername\AppData\Local\Programs\Python\Python36-32\Scripts\vba_extract.py
3.Now, you need to get the path of the .xlsm file you want to take from. If you don't have a .xlsm file made. Make one. Here is an example:
C:\Users\yourusername\Desktop\excelfilename.xlsm
4.Now, back to the Command Prompt. This is exactly what you will type. You will take both items from steps 2 and 3 and combine then and hit enter. Here:
C:\Users\yourusername\AppData\Local\Programs\Python\Python36-32\Scripts\vba_extract.py C:\Users\yourusername\Desktop\excelfilename.xlsm
if it is successful, it will tell you this:
Extracted: vbaProject.bin
5.For this one I'm not sure. I assume that wherever your .xlsm file is where the .bin file will end up. For this example, it ended up on my desktop. It will have all the macros you created or had on the original .xlsm file.
C:\Users\yourusername\Desktop/vbaProject.bin
Here is an example of it being used in full code:
import pandas
import xlsxwriter
df_new = pd.read_csv('C:\\Users\\yourusername\\Desktop\\CSV1.csv')
writer = pd.ExcelWriter('C:\\Users\\yourusername\\Desktop\\CSV1.xlsx')
df_new.to_excel(writer, index = False, sheet_name = 'File Name', header = False)
pandaswb = writer.book
pandaswb.filename = 'C:\\Users\\yourusername\\Desktop\\newmacroexcelfile.xlsm')
pandaswb.add_vba_project(r'C:\Users\yourusername\Desktop/vbaProject.bin')
writer.save()
I am trying to use xlwings for simple consolidation from several xls files.
For this, I have a all_files.xlsm file that contains a button with macros assigned to it. The macros looks like:
Sub check_data()
RunPython ("import python_code; python_code.consolidation()")
End Sub
In same folder I have a file python_code.py with function "consolidation" inside.
I also use Workbook.set_mock_caller() in order to have an opportunity to run a code through python interface. It looks like:
def consolidation(file_path):
*** smth to get the data I need ***
...
*** after I got data ***
Range('A1').table.clear_contents() #string1
Range('A1').value = data #string2
def main():
consolidation(file_path)
if __name__ == '__main__':
xl.Workbook.set_mock_caller(path_to_file)
main()
The problem is that when I am running the script through the button in excel file last two strings (string1 and string2) - Range('A1').table.clear_contents() and Range('A1').value = data doesn't work. Although the rest of the code works fine (however, it contains xlwing also). Moreover, if I run the script through the python interface using set mock caller, it works just fine, including string1 and string2 (marked in the code).
Any help and advices are really appreciated!
I found decision for my problem. For using xlwings in python you should import xlwings.bas in your excel file (see manual for xlwings). It turns out, that I imported it for this macros before I've updated xlwings. So I deleted this file and imported a new one. Everything works fine now.
When I run join.py on computer A, I get a properly joined 2 page PDF. When running it on computers B and C, I get a one page blank PDF. All three computers are MacBook Pros running 10.10.1
Running the following command from Script Editor, no errors occur:
do shell script "python '/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py' -o '/Volumes/SSD/Users/username/Desktop/CD123AD9-77DB-4678-B301-9498CFD4E344/Welcome Packet.pdf' /Volumes/SSD/Users/username/Desktop/CD123AD9-77DB-4678-B301-9498CFD4E344/*.pdf"
Any ideas on what is causing the joined PDF to come out as 1 page and blank?
This is an old post, but i had the exact same problem. After a lot of different attempts, eventually i managed to solve it (with the help of SO users ofc - thanks Marcomdm) in the following way:
I created a string with the necessary command parameters laid out:
stringToCall = "%s %s %s%s" % ("./join.py -o", endPdf, pdfInputDir,"/*.pdf")
os.chdir(/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/)
os.system(stringToCall)
where endPdf is the final pdf name coming from
endPdf = os.path.join (pdfOutputDir, pdfName+".pdf")
Worked like a charm. Hope this helps.