Make HTML table srollable - html

In a project report I want to enter some Dataframes.
Normally I generate the report with MarkDown but some tables are too wide to display nicely.
So I tried to export as in HTML with the code bellow:
# 1. Set up multiple variables to store the titles, text within the report
page_title_text='My report'
title_text = 'Scrollable table'
text = 'Hello, welcome to your Scrollable table test!'
prices_text = 'Twitter Data'
# 2. Combine them together using a long f-string
html = f'''
<html>
<head>
<title>{page_title_text}</title>
</head>
<body>
<h1>{title_text}</h1>
<p>{text}</p>
<h2>{prices_text}</h2>
{wrd_archive.head(5).to_html()}
</body>
</div>
</html>
'''
# 3. Write the html string as an HTML file
with open('html_report.html', 'w') as f:
f.write(html)
The output looks like the screenshot below and I am searching since hours for a solution how to make this table scrollable on the vertical axis and (that would be nice) scrollable vertical with a fixed height and fixed headers.
I do not know why I am lost today but I don't find the correct solution.
Can someone please help ;)
Screenshot

Related

Is there an attribute 'fit-to-page' in add_picture() using python docx

I have added a picture in a doc by using python docx. It looks good as long as it's small. But the picture goes next page or it's displayed half of it if the size is too big. How to make my picture 'fit-to-page'. I dont want to give any constants like Inches-5.5 or something.
p1 = doc.add_paragraph(' ')
pic = doc.add_picture(os.path.join(base_path, fi),
width=Inches(5.0))
para = doc.paragraphs[-1]
It's possible to get the text width, which is the page width minus the left and right margins, and pass this value to the width argument of add_picture().
An example of a function to get the text width is:
def get_text_width(document):
"""
Returns the text width in mm.
"""
section = document.sections[0]
return (section.page_width - section.left_margin - section.right_margin) / 36000
You can then call the function when adding a new picture:
r.add_picture(image, width=Mm(get_text_width(doc)))
If you need to add pictures in different sections of a document, it's necessary to improve the function to address this.
References:
How to change page size to A4 in python-docx
https://www.trichview.com/help/units_of_measurement.html#:~:text=English%20metric%20unit%20(EMU)%20is,%2C%201%20mm%20%3D%2036000%20EMU

Weasyprint not printing the pages spanning over more than one page

strong text
this is the code I am using to convert a rendered html page to pdf.
html_string = render_to_string("monthly_report/generated_pdf.html",
{'form': form, 'month': monthStr.strftime("%B %Y")})
html = HTML(string=html_string)
main_doc = html.render()
pdf = main_doc.write_pdf()
return HttpResponse(pdf, content_type='application/pdf')
The row having data spanning over more than one page is being truncated and data is getting lost.
What I want is the remaining data should be printed on the next page.
How it can be achieved ???
Please help, I am stuck over it from yesterday.
This problem is caused by bug #36, WeasyPrint is not able to split table cells yet.

Create word fields in python-docx to automatize footer from upon page 2 of the word document (e.g. # Page / # Total Pages)?

I'm trying to automatize a word - file generation via python docx. I created a template with the first page and its specific footers and headers; now I only need to implement this footer, starting from upon the second page:
Name Page # / Total Pages Date
all I want to know is how to configure this footer for all pages starting from the second, without influencing the headers or footers of the first page of the template. My problem is: Can I create word fields via python docx (e.g. the Pages and NumPages fields for the midpart; that's the only problem)..?
If not, can I somehow only insert the "Name" and the "Date" part into the footers from upon page 2 of the template without affecting the mid-part which I would then prepare in the template as well... ?
Attempted code on a template already containing the Pag/NumPag fields in the middle of the footer deleted the middle part (Result was a file where "Hello" was written in the lower left corner in the footer, and the Pag/NumPag of the template (Hello.docx) disappeared:
from docx import Document
from docx.enum.text import WD_ALIGN_PARAGRAPH
doc = Document("Hello.docx")
footer = doc.sections[0].footer
parag = footer.paragraphs[0]
parag.text = "Hello"
parag.alignment = WD_ALIGN_PARAGRAPH.LEFT
parag.style = doc.styles["Footer"]
doc.save("Hello2.docx")

Example to combine headers footers paragraphs of html and Tables

jspdf-autotable examples['header-footer'] example gets me most of what I need for my task.
I am trying to add rich text (constant font some bold and under line words) before and after a table. looking at examples.content did not make it clear.
So a complete PDF might be:
1. some paragraphs of text
2. a table on more than one page
3. some paragraphs of text
4. another table on more than one page
how do I combine all of this in one var doc = new jsPDF(); ?
Example code would be very appreciated.
The key is to use doc.autoTable.previous.finalY to get the final y position where the table ended drawing. You can than dynamically use that to draw text with doc.text(). If you want further guidence, please update your question with more info on what you have tried and what didn't work.

position oriented text and image save in Django/mysql

I'm creating a blog application similar to scoopwhoop or mensxp.
Basically I want to create my database in such a way that I can assign image a particular position in the article.
look at this page https://www.scoopwhoop.com/Move-Over-Tony-Stark-Marvels-New-Iron-Man-Is-A-15YearOld-Black-Girl/
or http://www.mensxp.com/health/weight-loss/31372-5-rules-of-fat-loss-that-most-people-ignore.html
you see, in these pages we have some text then a relevant image then again some text and relevant image to just above text and so on.
I mean it should make sense that a particular image comes just before or after the related text.
Currently I'm doing this way
class Post(TimeStamp):
title = models.CharField(max_length=127)
text = models.TextField(verbose_name='full text description')
# some more fields
class Pictures(TimeStamp):
image = models.ImageField(upload_to=upload_to_image_path)
post = models.ForeignKey(Post, related_name="picture")
this schema will create two tables one for blog post and other of images used in posts.
now here I can randomly put images in a post... like count no of words in a post and number of images associated with this post and then use basic math to divide the text in equal length and put images after every blog in frontend. but it wont solve the problem.
I tried to use django_summernote as well but created some other problems so discarded that option.
How do you think I should design my schema so that I can solve this problem and may be i should be able to use django admin smoothly.
I would throw out the Pictures() class altogether. The images should be a part of your post body. So an example entry would be...
title = "How to program an awesome site with Django!"
text = "<p>This is some text.</p><img src='image link'><p>This is some text after the image</p>"
Basically, the images are just as much a part of the post body as the text. There is no need to create a separate database table.
So in summary, this should be your database setup...
class Post(TimeStamp):
title = models.CharField(max_length=127)
text = models.TextField(verbose_name='full text description')
# some more fields
And the post body as a whole should all be contained within the text field.