0

I'm working a lot with Excel xlsx files which I convert using Python 3 into Pandas dataframes, wrangle the data using Pandas and finally write the modified data into xlsx files again.

The files contain also text data which may be formatted. While most modifications (which I have done) have been pretty straight forward, I experience problems when it comes to partly formatted text within a single cell:

Example of cell content: "Medical device whith remote control and a Bluetooth module for communication"

The formatting in the example is bold and italic but may also be a color.

So, I have two questions:

  1. Is there a way of preserving such formatting in xlsx files when importing the file into a Python environment?
  2. Is there a way of creating/modifying such formatting using a specific python library?

So far I have been using Pandas, OpenPyxl, and XlsxWriter but have not succeeded yet. So I shall appreciate your help!

As pointed out below in a comment and the linked question OpenPyxl does not allow for this kind of formatting:

Any other ideas on how to tackle my task?

  • Possible duplicate of [Editing workbooks with rich text in openpyxl](https://stackoverflow.com/questions/28774757/editing-workbooks-with-rich-text-in-openpyxl) – Charlie Clark Aug 15 '17 at 09:08
  • Thanks for pointing out the possible duplicate. – Vinz Frauchiger Aug 15 '17 at 17:51
  • If you work a lot with Xlsx files and dataframes I would recommend you to try the library [StyleFrame](https://github.com/DeepSpace2/StyleFrame) it won't help you to solve this specific problem but may make your work easier :) – AsafSH Aug 16 '17 at 21:08
  • Thanks for this input! I will check it out. – Vinz Frauchiger Aug 18 '17 at 07:34

1 Answers1

0

i have been recently working with openpyxl. Generally if one cell has the same style(font/color), you can get the style from cell.font: cell.font.bmeans bold andcell.font.i means italic, cell.font.color contains color object.

but if the style is different within one cell, this cannot help. only some minor indication on cell.value

Emma
  • 136
  • 2
  • 7