开发者

convert html table to csv

I have a complex html table that I would like to export as CSV. To start with, I am trying to figure out if this can be done on server side. Table is created using the StringBuilder and spitted out in a div.

Rule is that CSV has to be the created from the HTML markup in the browser not from model or data.

To be able to create CSV on server side, I am unable to determine how to get/access the exact markup from the browser in one action methods after clicking the save button.

For now there is not much to the code itself as I am trying to just access the table in the controller. but here is what it looks like: This is the request onclick for a button.

 $.ajax({
            async: false,
            url: "Application/Export",
            dataType: "html",
            type: "POST",
            success开发者_开发技巧: function (data) {
                alert(data);
            },
            error: function () { alert("Error!"); }
        });

Controller is empty for now:

   public string Export(string id)
    {
        //Convert to csv here
        return id;
    }

Any ideas?


Why on earth would you be required to use the HTML table and not data from the model? Please explain the reasoning behind this.

Edit: If you're screen scraping, then you'll need to grab the page via HTTP request, parse the HTML, then iterate over the parsed nodes while populating a CSV.


Take a look at jsoup: http://jsoup.org/ .

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜