Kali Chad
Kali Chad

Reputation: 21

Edit .xlsx with python

I Completely have no idea where to start.

I want to edit some think like:

enter image description here

To: enter image description here

I want to save the result in a .txt file.

Every thing i know is to open and read the file. code:

import pandas as pd
file = "myfile.xlsx"
f = pd.read_excel(file)
print(f)

I think the image colors speak for themselves how the code have to run. If not, I'll answer any question.

Upvotes: 0

Views: 680

Answers (2)

user13945859
user13945859

Reputation:

My go-to for editing Excel spreadsheets is openpyxl

I don't believe it can turn .csv or .xlsx/xlsm into .txt files, but it can read .xlsx/xlsm and save them as a .csv, and pandas can read csv files, so you can probably go from there

Quick example:

from openpyxl import load_workbook
wb = load_workbook("foo.xlsx")
sheet = wb["baz"]
sheet["D5"] = "I'm cell D5"

Upvotes: 1

Amiga500
Amiga500

Reputation: 1275

Use openpyxl, and look at this below:

Get cell color from .xlsx

color_in_hex = sh['A2'].fill.start_color.index # this gives you Hexadecimal value of the color  (in cell A2)

So you'd have to iterate across your columns/rows checking for a colour match, then if its a match, grab the value and apply it to your new sheet

Upvotes: 0

Related Questions