1
<table summary="merhaba" class="datagrid" id="tablo1" runat="server">
        <thead><tr>
            <th id="Th1" style="border:solid 1px #000000" runat="server">ad</th>
            <th id="Th2" runat="server">Soyad</th>
            <th id="Th3" runat="server">TC</th>
               </tr>
        </thead>
        <tbody>
            <tr>
                <td>ebrar</td>
                <td>bayburt</td>
                <td>999</td>
            </tr>
        </tbody>
    </table>

我可以添加行:

$('#button').click(function () {//tabloya veri ekleme
             $('#tablo1 > tbody:last')
               .append('<tr><td class="A">' +
               $('#ad_').val()
               + '</td><td class="K">' +
               $('#soyad_').val()
               + '</td><td class="A">' +
               $('#tc_').val()
               + '</td></tr>');

});

我可以使用以下代码将表格导出到 excel:

protected void Button1_Click2(object sender, EventArgs e)
        {
           Response.Clear();
            Response.AddHeader("content-disposition", "attachment;filename=myexcel.xls");
            Response.ContentType = "application/ms-excel";
            System.IO.StringWriter sw = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(sw);
            tablo1.RenderControl(hw);
            Response.Write(sw.ToString());
            Response.End();
         }

但是当打开 excel 文件时,我看不到从客户端添加的添加行,我只能看到我在代码中添加的那一行:

<tbody>
            <tr>
                <td>ebrar</td>
                <td>bayburt</td>
                <td>999</td>
            </tr>
        </tbody>

我曾经问过这个问题

我将 html 表导出到 Excel 的第一个问题

但是我必须用jquery添加行,添加后我必须将html表导出到excel中,里面装满了添加的行,有什么办法吗?

4

1 回答 1

0

这是因为您的 c# 代码是后端,并且不知道您已经操作了 DOM。您需要在 jQuery 而不是 c# 中创建您的 excel 文件。

这可能会帮助你。 http://forum.jquery.com/topic/jquery-create-excel-file-from-table-data

于 2013-04-10T15:50:00.773 回答