HTML表格生成器
生成带自定义行、列和样式选项的HTML表格标记。
Cell Content
HTML 输出
表格预览
| Header 1 | Header 2 | Header 3 |
|---|---|---|
| Cell 1,1 | Cell 1,2 | Cell 1,3 |
| Cell 2,1 | Cell 2,2 | Cell 2,3 |
| Cell 3,1 | Cell 3,2 | Cell 3,3 |
关于此工具
HTML表格生成器是一个简单实用的工具,可以生成格式正确的HTML表格标记,无需手动编写代码。无论您是在构建网站、向博客文章添加数据,还是记录结构化信息,该工具都让您可以直观地定义表格结构,并生成干净、符合标准的HTML代码,您可以直接粘贴到编辑器或内容管理系统中。
首先指定行数和列数,然后使用交互式表单填充单元格内容。该工具提供边框、填充和标题行格式等样式选项,使您在复制代码之前就能看到表格的完成效果。对布局满意后,只需复制生成的HTML并将其粘贴到需要的位置即可,无需任何外部库。
这个工具特别适用于想要避免重复输入的开发人员、将数据嵌入文章的内容创作者,以及想要学习HTML表格结构的初学者。即时预览确保您看到确切的结果,而定制外观的功能意味着您可以将其调整到项目的设计中,而无需手动CSS调整。
常见问题
代码实现
# Generate an HTML table from a list of dicts
def generate_html_table(headers, rows, border=True, stripe=False):
border_attr = ' border="1" style="border-collapse:collapse"' if border else ""
lines = [f"<table{border_attr}>", " <thead><tr>"]
for h in headers:
lines.append(f" <th>{h}</th>")
lines.append(" </tr></thead>", " <tbody>")
for i, row in enumerate(rows):
bg = ' style="background:#f2f2f2"' if stripe and i % 2 == 0 else ""
lines.append(f" <tr{bg}>")
for cell in row:
lines.append(f" <td>{cell}</td>")
lines.append(" </tr>")
lines.append(" </tbody>", "</table>")
return "\n".join(lines)
headers = ["Name", "Age", "City"]
rows = [["Alice", 30, "New York"], ["Bob", 25, "London"]]
print(generate_html_table(headers, rows, border=True, stripe=True))Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.