Convert excel sheets with images to PDF files - python

I'm trying to automate a process that converts excel files with single sheets having charts into pdf files using python. Any packages available that would help this task?
I have tried Excel Writer and other similar packages, it doesn't seem to work.
Reading the file using pandas doesn't work.
The source file has charts/images.
PDF file for each excel file is the desired output. Any suggestions would be welcome..

Related

python excel sheet saves as pdf

I want to save my excel sheets (there are more than 50 sheets) in a separate PDF file and each file name should be saved in the sheet name. I can do it by excel VBA but I was curious whether it can be done in python.
pywin32 will do the job for you. Please follow this link.

How can I change the format of just one sheet of an excel workbook using python?

I have large excel files with format .xlsb and .xlsx. I need to read only one sheet from all these files in python. It takes forever to use read_excel on these files. I want to save off that sheet I need as a .csv file and then read it to make it quicker. The only problem is that I have 24 of these excel workbooks and I don't have the time to manually take that sheet for each workbook and save it as .csv. Any suggestions on how I can change the format of just that one sheet?
An .xlsx-file is technically a folder. It is possible to open it as a zip-file and extract the individual sheets. However, I have never attempted to do this using Python, so I do not know how easy it is to do.

How to convert .wfs files into .csv

I have thousands of .wfs(windows script files) files and I am looking for a solution to help me convert this huge amount of .wfs files into .csv files using Python Anaconda or Spyder.
May I know any IO API similar to pandas where could read wfs files using similar functions like read.excel? or does python read script files?
Or could I convert these script files into Excel read quick (I know how to convert excel files into csv using Python)?
An example .wfs along with the converted csv is contained in the link below:
https://www.dropbox.com/sh/uwbajpubzuxn7g5/AABbD7W4pXFlxiIi1UAlHKTFa?dl=0

Error opening text file saved with .xls extension in python

I'm using labview to create and save data from an experiment. Labview itself creates a text file but saves it automatically with a .xls extension (word 1997-2003--it's an old setup that was never changed because it never broke). Whenever I go to open one of the data files, excel spits out this:
"The file you are trying to open, 'name.ext', is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?"
I'm generating a lot of data, so I want to use python to sort it out and do some quick analysis over files in a directory.
The problem is that python doesn't like that it's a text file saved with a .xls extension. It can cycle through the directory just fine to get the file names, but whenver I actually try to open the file or do anything with it, I get the error in the image attached. This happens if I change the extension to .xls, .xlsx, or do nothing with it at all and let it try to open the original filename.
error message
I literally have hundreds of these .xls files. I know I can go through, open each one in excel and save as a real excel file by hand, but that will take hours. Can someone please help me figure a way around this error in python?
Dropbox Data File set
*Update. Matlab, when trying to read one of the files using xlsread, says this:
Error using xlsread (line 251)
File C:\Users\zane\Documents\Research Projects\PneuFish Project\Data\Nov 28 2016 ATI
Data\ATI_Data_2016Y_11M_28D_16h_36m_01s.xls not in Microsoft Excel Format.
Thank you!
You can use the module xlrd.
import xlrd
import csv
def csv_from_excel():
wb = xlrd.open_workbook('your_workbook.xls')
sh = wb.sheet_by_name('Sheet1')
your_csv_file = open('your_csv_file.csv', 'wb')
wr = csv.writer(your_csv_file, quoting=csv.QUOTE_ALL)
for rownum in xrange(sh.nrows):
wr.writerow(sh.row_values(rownum))
your_csv_file.close()
Taken from This Post
This will convert from .xls to .csv, which is easily manipulated with Python.
You've said that the file is a text file, so don't tell Python that it's an Excel file. Just use Python's open and read it as text, then do whatever you want with it. open doesn't care what extension a file has.
I'm going to guess that the format is actually tab-delimited. From memory, earlier versions of Excel would read in tab-delimited text files with the .xls extension without complaint, whereas csv files would always bring up the text import wizard, so this was a common dodge if saving data intended for Excel from a program that didn't support writing real Excel files.
If you want the LabVIEW code to write real Excel files in future, the Write to Measurement File express VI has an option to write in xlsx format. I'm not sure which version of LabVIEW first introduced this but it's been there for a few years now.

Complicated Excel Issue with Google API and Python

So I know how to download Excel files from Google Drive in .csv format. However, since .csv files do not support multiple sheets, I have developed a system in a for loop to add the '&grid=tab_number' to the file download url so that I can download each sheet as its own .csv file. The problem I have run into is finding out how many sheets are in the excel workbook on the Google Drive so I know how many times to set the for loop for.
Ended up just downloading with xlrd and using that. Thanks for the link Rob.

Categories

Resources