Not being able to write a data frame to a excel sheet - excel

This is the error message i am getting .Even on trying the code given by my tutor and online i tried fixing but ended up being not able to fix the problem

You're requesting Pandas to use the xlsxwriter engine to write your XLSX file. The error says
ModuleNotFoundError: No module named 'xlsxwriter'
To use the xlsxwriter engine, you'll need to install the xlsxwriter module.
Usually, that's done with pip install xlsxwriter.

Related

Powerpoint PPT File to PPTX Using Python

I have been searching the web for hours trying to find something that might help me convert a file that was saved in the ppt file type to the pptx file type using python. I found "python-pptx" and was planning on using it to save the files, however this was not possible due to the continuous error:
Package not found at 'FileName.ppt'
I discovered another post (Convert ppt file to pptx in Python) which did not help me at all. I assume it is because my python version might be too high. (3.9) After reading up on getting the win32com.client to work and installing multiple pip and pip3 commands, it is still not working. If anyone could assist me with this manner I would be very thankful. My Current Code:
from pptx import *
prs = Presentation("FileName.ppt")
prs.save("FileName.pptx")
You can use Aspose.Slides for .NET and Python.NET package for converting PPT to PPTX as shown below:
import clr
clr.AddReference('Aspose.Slides')
from Aspose.Slides import Presentation
from Aspose.Slides.Export import SaveFormat
# Instantiate a Presentation object that represents a PPT file
presentation = Presentation("presentation.ppt")
# Save the presentation as PPTX
presentation.Save("presentation.pptx", SaveFormat.Pptx)
Our web applications use our libraries and you can see conversion results here.
I work at Aspose.
I doubt python-pptx can parse a .ppt file. (It's a completely different file format.) You're better off automating PowerPoint itself - somehow - to read one and write the other.
The "somehow" depends on the platform you're running on - and the automation capabilities available to you.

Query regarding pandas

Even after installing xlrd module, I am not able to read excel files using pandas, every time it's showing file directory not found. Please help!
I am using " import Pandas as pd"
" data=pd.read_excel("notebook.xlsx")
It shows error as file not found
Pandas is not finding the excel file. Try to put the complete path on the read_excel function like read_excel("C:/documents/notebook.xlsx").

Losing images after loading and saving a workbook in openpyxl

from openpyxl import load_workbook
input_file = "input.xlsx"
output_file = "output.xlsx"
wb = load_workbook(input_file)
wb.save(output_file)
My input file contains some image file. But while loading it and saving it again all the images are lost from my excel workbook. Please resolve this issue.
Thank you
I encountered the same problem until I installed the library Pillow.
Check it out: https://pillow.readthedocs.io/en/stable/installation.html
either add it to your requirements.txt or install it using the command
pip install Pillow>=8.3.2
Hope that helped ^^
As of now, openpyxl does not read all elements present in a Excel file. (See official openpyxl docs: https://openpyxl.readthedocs.io/en/default/usage.html)
Essentially, your images aren't showing up because openpyxl doesn't know how to read images.
Try using an alternative library like XlsxWriter (PyPi Page: https://pypi.org/project/XlsxWriter/)
Hope this answer helps!
Happy Coding ~

xlwings : Object Required

I'm a newbie into both python and xlwings. So the story is,
I need a custom function needs to be used in Excel. Since I have no clue about VB scripts, I decided to write a function in python and import it in excel using xlwings.
I installed xlwings using the pip command. I added the addin to excel
by the procedure given in xlwings support forum.
I created an excel file, say " Test.xlsm". I created a python file in
the same name "Test.py" (File is in same folder only)
I wrote my function in the python
import xlwings as xl
#xl.func
def exponent(x,y):
#the function is an example only. I tried this for practicing and it is also not working
z=x**y
return z
I opened excel, imported the functions using import function in
xlwings addin. I found no errors in importing the functions
I called the functions from the excel cell,
"=exponent(A1,B1)"
Instead of getting a result, I'm getting "Object Required"
I don't know what went wrong?
Any ideas what I'm missing? Forgive me for the basic question.
You need to add the Reference in VBA.
Open up the Developer console (Alt-F11)
Click on Tools -> References and select xlwings

cannot use LOCALE flag with a str pattern

import xlwt
wb = xlwt.Workbook()
sheet1 = wb.add_sheet('Sheet 1')
wb.save('self, example.xls')
I am trying to learn how to create xls, edit xls, or delete if neccesary on python. I had verymuch trouble on this because every tutorial online doesn't mentions that I should put xlwt before Workbook but I figure it out now. The problem is when I run this code I get an error wich it says "ValueError: cannot use LOCALE flag with a str pattern" I don't even know what that means... What is it about and how can I fix it?
There is a known-issue with tablib and Python 3.6, looks like it will be solved in the next releases.
For now, I make it work just downgrading to python 3.5.2
I had a similar problem and i resolved it by changing my series to "str" data type. df.astype("str")
Also not sure why you are trying to save your file as "self, example.xls". Could you print the entire error as it was given.

Resources