Python Forum
How to obtain the background color of a cell using xlrd?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to obtain the background color of a cell using xlrd?
#1
Hi all,

I wat to get the background color of a given cell with python from an xlsx. Iam new with it, could you please help me to finish this :

import xlrd
workbook = xlrd.open_workbook('67.xlsx')
worksheet = workbook.sheet_by_name('Oldal1')
# read a cell
cell = worksheet.cell(2,2)
#print cell
print cell.value
Reply
#2
First you need to open the sheet with the formatting_info set to true

import zlrd
wb = xlrd.open_workbook(<filename>, formatting_info=True)
ws = wb.sheet_by_name(<sheet name>)
c = ws.cell(1, 1)
cif = ws.cell_xf_index(1, 1)
iif = wb.xf_list[cif]
cbg = iif.background.pattern_colour_index
print(cbg)
That should do the trick
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Selecting correct xlrd version Kithsiri 4 446 Feb-27-2024, 07:09 AM
Last Post: Kithsiri
  Turtle Star Fill Color Yellow-White Interchanging Color Effect codelab 9 903 Oct-25-2023, 09:09 AM
Last Post: codelab
  Color a table cell based on specific text Creepy 11 1,841 Jul-27-2023, 02:48 PM
Last Post: deanhystad
  Python Resampling: How do I obtain the value of the last week of the month? JaneTan 2 973 Dec-12-2022, 12:49 AM
Last Post: JaneTan
  Use of input function to change screen background color in Turtles Oldman45 3 4,744 Jul-10-2020, 09:54 AM
Last Post: Oldman45
  Does "import xlrd" work in Thonny? cnutakor 3 2,947 Apr-30-2020, 12:41 AM
Last Post: Larz60+
  Sequential color background swisha 2 1,986 Mar-05-2020, 03:43 PM
Last Post: Larz60+
  Issues installing xlrd KipCarter 2 2,781 Jan-24-2020, 12:20 PM
Last Post: KipCarter
  how to obtain header, data, pararms zarize 4 2,337 Sep-30-2019, 08:17 AM
Last Post: zarize
  XLRD Package not be able to call dhiliptcs 2 2,267 Sep-24-2019, 05:21 PM
Last Post: dhiliptcs

Forum Jump:

User Panel Messages

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