Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to resume \n read from excel file in output pdf file – reportlab python

I am trying to read from excel file and generate the output file using reportlab library in python. Now the text in excel file is as below :-

enter image description here

When I am reading it into pdf I am not able to resume newlines.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

Below is the code I am using for the same :-

for body_column in body_columns:
    body_para = Paragraph(f'{body_column}', style['BodyText'])
    details.append(body_para)
                
doc.multiBuild(details)

Could anyone please help me with this?

>Solution :

When you’re using the paragraph with reportlab, it treats your text like HTML. This means that it doesn’t interpret \n as a new line. Instead, you could replace the ‘\n’ with ‘< br/ >’ (without the spaces), as such:

for body_column in body_columns:
   body_column = body_column.replace('\n', '<br/>')
   body_para = Paragraph(f'{body_column}', style['BodyText'])
   details.append(body_para)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading