1

I am working on a legacy python system, which accepts dataframe and extracts certain numeric measures out of it. It then uses a excel template, creates a table based on the template and outputs the screenshot of it as a png. Through out this, it uses various windows specific packages like pywin32 and com objects.

We are now planning to move the system to linux from Windows and as part of it, trying to get rid of windows packages. Can anyone help me how can I create something as shown in the image using python packages or libraries without using excel templates and pywin packages?

Since its confidential, I cannot show the exact output, but it would look something in line with the attached image. The highlighted parts are the conditional formats on each column based on a threshold.

enter image description here

James Z
  • 12,209
  • 10
  • 24
  • 44
triki
  • 11
  • 7
  • Have you tried using csv library? it has a support for Excel dialect and is OS agnostic. If you've columns which have multiple lines in the same, you need to set correct encoding i.e. utf-8-sig – Hussain Bohra Nov 23 '19 at 00:59
  • There's probably better solutions but at the very least, you could just build an HTML document with a Table. – David Zemens Nov 23 '19 at 00:59
  • I will check the csv library @HussainBohra. Is there a documentation or a reference which helps me learn how can I do that @David? – triki Nov 23 '19 at 01:11
  • Perhaps you should have a look at pandas' [`dataframe.style`](https://pandas.pydata.org/pandas-docs/stable/reference/style.html) topic. Things like Excel's conditional formats can there be done, too. With the `render` method you'd get a html representation. – SpghttCd Nov 23 '19 at 08:50
  • Possible duplicate of [Using Python to Automate Creation/Manipulation of Excel Spreadsheets](https://stackoverflow.com/questions/1140311/using-python-to-automate-creation-manipulation-of-excel-spreadsheets) – guidot Nov 23 '19 at 09:25
  • Yeah, use pandas dataframe probably. CSV works with excel, but that is still going to require COM. There are wrappers that can create the OpenXML Workbook Format in COM-less environments, but you won't be able to simulate "opening the workbook and exporting a range of cells to PNG" without COM. – David Zemens Nov 23 '19 at 14:16
  • You may want to rethink your process as well. Mainly: do you really need PNG? Why? Static image files are a pretty lousy way to transmit or convey tabular data in nearly all cases. – David Zemens Nov 23 '19 at 14:19
  • Hey David, the application requires png files to be attached into a report. I have been looking through the dataframe styling which I believe is close to what I require. i am just wondering how could I save the final output of styling as an image. – triki Nov 25 '19 at 17:49
  • Thanks for the suggestion @SpghttCd. I really appreciate your help. – triki Nov 25 '19 at 17:50

0 Answers0