Sep-10-2019, 06:51 PM
Hi,
so I have a running invoice program that functions ok. But I want to tweak it to run better for me.
But having a couple of problems
Problem 1. I want to save as a docx file from the excel. It does this, but when I open the newly created docx file it says:
Word found unreadable content in demo1.docx. Do you want to recover contents of this doc?
All attempts to recover contents fail.It only has the new invoice number in it per program below ( this is a stripped down version of my program to try and solve the problems I want fixing ). So something I am trying to do causing this.
Problem 2. I want to save the file with the new invoice number as part of the filename. When I try the bottom 2 lines of the program below ( both#'ed at the moment ), with copyfile it does save but the new file is called +str(new_invoice_number)+.docx ie it doesn't insert the actual number of new_invoice_number.
With os.renames it errors with:
SyntaxError: EOL while scanning string literal, indicating the last closing parenthesis.
Any pointers?
Thank you
so I have a running invoice program that functions ok. But I want to tweak it to run better for me.
But having a couple of problems
Problem 1. I want to save as a docx file from the excel. It does this, but when I open the newly created docx file it says:
Word found unreadable content in demo1.docx. Do you want to recover contents of this doc?
All attempts to recover contents fail.It only has the new invoice number in it per program below ( this is a stripped down version of my program to try and solve the problems I want fixing ). So something I am trying to do causing this.
Problem 2. I want to save the file with the new invoice number as part of the filename. When I try the bottom 2 lines of the program below ( both#'ed at the moment ), with copyfile it does save but the new file is called +str(new_invoice_number)+.docx ie it doesn't insert the actual number of new_invoice_number.
With os.renames it errors with:
SyntaxError: EOL while scanning string literal, indicating the last closing parenthesis.
Any pointers?
Thank you
from openpyxl import load_workbook import docx import os from shutil import copyfile wb = load_workbook(r"C:\Users\Ron McMillan\Desktop\demo1.xlsx") #opens the existing spreadsheet sh = wb['Sheet'] invoice_number = sh['A4'] #takes existing invoice number print (invoice_number.value) new_invoice_number = invoice_number.value + 1 #increments existing invoice number print(new_invoice_number) sh['A4'] = new_invoice_number #writes new invoice number into sheet wb.save(r'C:\Users\Ron McMillan\Desktop\demo1.xlsx') #saves workbook wb.save(r'C:\Users\Ron McMillan\Desktop\demo1.docx') #saves as docx #copyfile(r'C:\Users\Ron McMillan\Desktop\demo1.xlsx',r'C:\Users\Ron McMillan\Desktop\+str(new_invoice_number)+.docx') #os.renames(r'C:\Users\Ron McMillan\Desktop\demo1.xlsx',r'C:\Users\Ron McMillan\Desktop\'+ str(new_invoice_number) +'.xlsx')