Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
General Python code for Newbie
#11
(Apr-26-2017, 09:24 PM)joe_anonimist Wrote: Openpyxl is not able to add annotations to Excel cells (afaik).
It allows you to change cell styles. Looks like it has what the OP needs (took me a couple of minutes to find)


Quote:Excel COM API is not obscure it is the official Microsoft Excel automation API
pywin32 is obscure module, designed to work on Windows only, supported up to 3.3  - and what if, god forbids Naughty OP works on Linux?

As far as Excel COM API - frankly speaking, I don't know much about Excel Blush , but it's an extra tool to learn. And knowing Microsoft, and judging by your response, it's not something that you can do "quick'N'dirty" Doh .

openpyxl is pretty straightforward Python package supported in all available Python versions. It took me just  couple of hours to start working with (and my code does run on Linux)
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply
#12
(Apr-27-2017, 12:01 AM)volcano63 Wrote: As far as Excel COM API - frankly speaking
pywin32 is obscure module, designed to work on Windows only, supported up to 3.3 
I agree that there are much better tool for Excel than trough COM API with Pywin32.
Pywin32 work over 3.3,it's support all the way to Python 3.7 and Gohlke has wheel up to 3.6.

Openpyxl is okay,probably the best tool is Pandas which read Excel.
Quick test.
import pandas as pd

df_1 = pd.read_excel('book1.xlsx')
df_2 = pd.read_excel('book2.xlsx')
Test:
>>> df_1
   a  b  c
0  1  2  3

>>> df_2
   a  b  c
0  1  4  5
Pandas has a lot of tool for comparing diff,equal,merge..ect.
dataframes with are identical(row/column) be compared with eg  ==
>>> df_1.equals(df_2)
False

>>> df_1 == df_2
      a      b      c
0  True  False  False
>>> df_1 != df_2
       a     b     c
0  False  True  True

# Compare singe cell
>>> df_1['a'].equals(df_2['a'])
True
>>> df_1['b'].equals(df_2['b'])
False
>>> df_1['a'].equals(df_2['c'])
False
Reply
#13
(Apr-27-2017, 03:55 PM)snippsat Wrote: Openpyxl is okay,probably the best tool is Pandas which read Excel.
OP don't have just to read Excel, he has to update it and write back it too. My company's SW architect claims that openpyxl is better than pandas
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply
#14
(Apr-27-2017, 04:23 PM)volcano63 Wrote: OP don't have just to read Excel, he has to update it and write back it too.
Pandas can of course do that df.to_excel()
Quote:My company's SW architect claims that openpyxl is better than pandas
That can be a personal preference and depend on what task to be solved,
if look into it Pandas is more powerful that almost all tool out there.

Working with Juypter notebook a Pandas dataframe look just like Excel which is convenient.
As shown here Common Excel Tasks Demonstrated in Pandas
Reply
#15
Excel files manipulation is only complementary feature for pandas, while for openpyxl its only reason to exist. Pandas internally uses either XlsxWriter (default writer for xlsx), openpyxl (default for .xlsm) or xlwt (old .xls) for manipulating excel files, so i would guess that for "low level" work with excel these tools would be more appropriate and more powerful.

As snippsat said, it depends on task - for visual changes or specific cells manipulation you probably wont use pandas, while for loading and processing tabular data you probably would. And if task needs both heavy data lifting and heavy excel lifting, nothing stops you from using both pandas and openpyxl.
Reply
#16
(Apr-27-2017, 04:54 PM)snippsat Wrote:
(Apr-27-2017, 04:23 PM)volcano63 Wrote: OP don't have just to read Excel, he has to update it and write back it too.
Maybe update was unfortunate word - OP needed means to change cell formatting. Can pandas do it?

Again, pandas is a little bit more complicated... On a quick learning curve openpyxl is easier. The guy was not looking for a powerful tool...
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply
#17
Hi all, I am new to python. I have a requirement as:
I have to download multiple excel files from google drive using python code
and while downloading, i have to add date to each file name. 
Excels may be many. 
Can any one has any idea. please give me instructions, and i will work.
Q1. Using python code how can i login to google.

Thank you all in advance,
Reply
#18
There's the api (python client provided by google) here: https://developers.google.com/drive/v3/w...art/python
Then there's also a convenience wrapper for google drive: https://pypi.python.org/pypi/PyDrive

The examples of the second one make it look very easy to download files. That seems like a decent place to start.
Reply
#19
You're likely going to need third party libraries and extra knowledge to be able to do this. For a start you'll need to use Google's HTTP APIs to get access to the data (so you'll need to have some understanding of HTTP APIs) and then you'll have to use some library that lets you manipulate Excel files (I don't know of any).

Given you say you're a newbie, how much experience programming do you really have? Is this not too complicated a task for you for right now?
Reply
#20
(Apr-26-2017, 10:03 PM)Larz60+ Wrote:
Quote:So they gave this task.

If (for real) someone did that to me, I'd quit within the next hour,
or perhaps not show up for a few days like in the movie 'Office Space'
We should not escape from the problem. We have to face the problem. Otherwise they will consider us as defeated. So i took it as challenge
and requested your help.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Newbie Needs Help with Python Port to Web RobertL 1 2,181 May-09-2020, 10:50 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020