开发者

Save html table into excel [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I must write a program that periodically re开发者_StackOverflow社区ads a web page and copies certain data from a table on that page to an Excel spreadsheet. I don't know where to start or what programming language is suitable for this project. I know a little C++ and Matlab programming. Can anyone offer advice to point me in the right direction or suggest open source projects which do something similar?


To expand on Oliver's point, if you can get the table data in an XML file to begin with, Excel allows you to create a "template" for yourself that maps the XML file's nodes to various cells. Then you'd simply update your XML data.

Of course we're assuming your data is coming from an external data source.


Maybe this will work..

<html>
<head>
<script type="text/javascript">
    function CreateExcelSheet() {
        var x = myTable.rows;

        var xls = new ActiveXObject("Excel.Application");
            xls.visible = true;
            xls.Workbooks.Add;
        for (i = 0; i < x.length; i++) {
            var y = x[i].cells;
            for (j = 0; j < y.length; j++) {
                xls.Cells( i+1, j+1).Value = y[j].innerText;
            }
        }
    }
</script>
</head>
<body>

<form>
    <input type="button" onclick="CreateExcelSheet()" value="Create Excel Sheet">
</form>

<table id="myTable" border="1">
    <tr>
        <td>Name</td>
        <td>Age</td>
    </tr>
    <tr>
        <td>Shivani</td>
        <td>25</td>
    </tr>
    <tr>
        <td>Naren </td>
        <td>28</td>
    </tr>
    <tr>
        <td>Logs</td>
        <td>57</td>
    </tr>
    <tr>
        <td>Kas</td>
        <td>54</td>
    </tr>
    <tr>
        <td>Sent</td>
        <td>26</td>
    </tr>
    <tr>
        <td>Bruce</td>
        <td>7</td>
    </tr>
</table>

</body>
</html>


I would probably do this by reading the webpage as if it were an XML document, and converting the relevant sections into .csv format. You could do this in many different languages, and .csv is a very simple and easy format to work with.

I don't know how good Matlab is for dealing with XML and web stuff, but C/C++ tend to be really bulky and unwieldy for this kind of thing. If you want to try learning another programming language to do it with, try Python - its easy to use an very intuitive for dealing with XML and web stuff. You could use its HTML Parser to find the right elements of the page, and do some simple file writing to put it into .csv format.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜