2016-02-13 64 views
0

我有一个包含足球统计数据的excel文件,我希望能够更改excel数字,并且这样做时网站会自动更新其表格。如何将Excel中的数据插入到html表格中?

有没有可能的方法来做到这一点?

+0

你在用什么? PHP的? java吗? ASP? –

+0

@SariAlalem我正在使用准系统的HTML和CSS,与一些JavaScript?我还没有开始学习任何PHP等。 –

+2

那么,为了能够处理一个文件(读取它的数据),你需要一个后端脚本/程序来做到这一点,这可以用php,java等完成。或者你可以使用html5/javascript File API ,这是更困难的,请参阅http://stackoverflow.com/questions/8238407/how-to-parse-excel-file-in-javascript-html5 –

回答

1

这并不能完全回答你的问题,但我想把它作为一个部分答案。我有一个通用程序(方法),我不时使用它将Excel Table(又名ListObject)转换为HTML表格。 Perl有一个出色的模块,但我从来没有发现类似于VBA的东西,因此我的手卷代码。

唯一需要注意的是您的数据必须在表格中。如果它来自RDBMS,那么最简单的方法就是通过MS Query将其引入,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 

是的,这是非常蛮力的。

+0

还有更简单的解决方案。您可以将CONCATENATE用于HTML标记,并将它们与HTML一起复制/粘贴到.htm文件中 – IgorM

相关问题