Is there a way to automatically create an HTML file and insert Excel data to it?

Viewed 20

I'll try to explain simply.

I have an excel file that has some data that I want to use. It has 4 columns namely: Picture, Name, Description, and Piece. I also have some sample HTML code with placeholders inside. What I wanna do is possibly automatically create a new file and insert the HTML code along with the data in the excel file, and do this per row in the excel file.

If there is no way to auto-create files or it is way too complex, well I can always create the files myself but still automate the inserting data process.

Now, I do have some idea on how to do this. I could probably use a python script to do it but I don't really know python except for a beginners class from 1st year high school, and I can't seem to find a reliable resource...

If you have any code that I can use then that'll be very great! thank you in advance~

some context: these files that I wanna auto create are for a simple HTML static website. The people in the excel file btw are composers of the Classical era (e.g. Beethoven, Mozart...)

1 Answers

Dominate is a Python library for creating HTML documents and fragments directly in code. This example appears on the same page as an illustration of what this package can do.

I found this by googling 'create HTML in Python' and finding this , which I upvoted.

Stack Overflow appreciates it, when we research solutions to our questions before we ask them.

import dominate
from dominate.tags import *

doc = dominate.document(title='Dominate your HTML')

with doc.head:
    link(rel='stylesheet', href='style.css')
    script(type='text/javascript', src='script.js')

with doc:
    with div(id='header').add(ol()):
        for i in ['home', 'about', 'contact']:
            li(a(i.title(), href='/%s.html' % i))

    with div():
        attr(cls='body')
        p('Lorem ipsum..')

print(doc)

Output

<!DOCTYPE html>
<html>
  <head>
    <title>Dominate your HTML</title>
    <link href="style.css" rel="stylesheet">
    <script src="script.js" type="text/javascript"></script>
  </head>
  <body>
    <div id="header">
      <ol>
        <li>
          <a href="/home.html">Home</a>
        </li>
        <li>
          <a href="/about.html">About</a>
        </li>
        <li>
          <a href="/contact.html">Contact</a>
        </li>
      </ol>
    </div>
    <div class="body">
      <p>Lorem ipsum..</p>
    </div>
  </body>
</html>
Related