【问题标题】:How would I insert data from excel into a html table?如何将excel中的数据插入到html表中?
【发布时间】:2016-02-13 10:53:47
【问题描述】:

我有一个包含足球统计数据的 excel 文件,我希望能够更改 excel 数字,并且网站会自动更新其表格。

有没有办法做到这一点?

【问题讨论】:

  • 你在用什么? php?爪哇? ASP?
  • @SariAlalem 我正在使用准系统 html 和 css,以及一些 Javascript?我还没有开始学习任何 php 等。
  • 好吧,为了能够处理文件(读取其数据),您需要一个后端脚本/程序来执行此操作,这可以通过 php、java... 等来完成。或者您可以使用html5/javascript文件API,比较难,见stackoverflow.com/questions/8238407/…
  • 如果您尝试从 Excel 表格更新网站,您可以编写 VBA 代码,将文件内容导出为 CSV 文件,然后使用 JavaScript 将其推送到网站
  • 感谢大家的帮助

标签: html sql database excel


【解决方案1】:

这并不能完全回答您的问题,但我想将其作为部分答案。我有一个通用程序(方法),我不时使用将 Excel Table(又名 ListObject)转换为 HTML 表格。 Perl 有一个模块可以很好地做到这一点,但我从来没有发现任何类似的 VBA 的东西,因此我的手卷代码。

唯一需要注意的是您的数据必须在表格中。如果它来自 RDBMS,那么最简单的做法是通过 MS Query 将其引入,它会自动将输出呈现为 Table/ListObject。

我知道你在谈论 Web 并没有提到 VBA —— 只是把它当作它的价值。我希望它有一些你可以收集到的有用组件。

Function TableToHtml(ByRef Table As ListObject, Title As String) As String

  Dim row As ListRow
  Dim header, col As range
  Dim output As String

  output = _
    "<html>" & vbCrLf & _
    "  <head>" & vbCrLf & _
    "    <title>" & vbCrLf & _
    Title & vbCrLf & _
    "    </title>" & vbCrLf & _
    "  </head>" & vbCrLf & _
    "<body>" & vbCrLf & _
    "<font size=""5"">" & Title & "</font><br><br>" & vbCrLf & _
    "<table border='1px' cellpadding='5' cellspacing='0' style='border: solid 1px Black; font-size: small;'>"

  output = output & "<tr align='center' valign='top'>" & vbCrLf

  Set header = Table.HeaderRowRange
  For Each col In header.Columns
    output = output & "  <td align='center' valign='top'>" & col.Value & "</td>" & vbCrLf
  Next col

  output = output & "</tr>" & vbCrLf

  For Each row In Table.ListRows
    output = output & "<tr align='left' valign='top'>" & vbCrLf
    For Each col In row.range.Columns
      output = output & "  <td align='center' valign='top'>" & col.Value & "</td>" & vbCrLf
    Next col
    output = output & "</tr>" & vbCrLf
  Next row

  Dim o As Object

  output = output & "<tr align='left' valign='top'>" & vbCrLf
  For Each header In Table.TotalsRowRange
    output = output & "  <td align='center' valign='top'>" & header.Value & "</td>" & vbCrLf
  Next header
  output = output & "</tr>" & vbCrLf

  output = output & "</table>" & vbCrLf & "</body>" & vbCrLf & "</html>"
  TableToHtml = output

End Function

是的,这很暴力。

【讨论】:

  • 还有更简单的解决方案。您可以使用 CONCATENATE 到 HTML 标记,然后它们将带有 HTML 的列复制/粘贴到 .htm 文件中
猜你喜欢
  • 2010-12-06
  • 2012-08-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-07
  • 1970-01-01
  • 2020-11-13
  • 2012-05-19
相关资源
最近更新 更多