Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying and renaming excel files with Python [duplicate]

I am trying to copy an excel file and rename it. For example I have a file HI.xlsx and I want to copy it and rename it as BYE.xlsx.
My code to do this is below and when I run it, the file BYE.xlsx is created, but it is corrupted.

Here is what I am using:

fIn = open(r"HI.xlsx")
fOut = open(r"BYE.xlsx", "w")
like image 738
Horv Avatar asked Dec 18 '15 14:12

Horv


People also ask

How do you copy an Excel spreadsheet in python?

Below you can see code example. Copy def copy_worksheet(self): \# Instantiating a Workbook object by excel file path workbook = self. Workbook(self. dataDir + "Book1.


1 Answers

You should be using shutil.copy():

shutil.copy("HI.xlsx", "BYE.xlsx")
like image 68
DeepSpace Avatar answered Sep 18 '22 04:09

DeepSpace