如何将数据从引导卡导出到Excel工作表?

时间:2019-03-01 06:56:38

标签: c# mysql asp.net twitter-bootstrap bootstrap-4

我已将数据从数据库绑定到一组引导卡。我需要将这些导出到Excel工作表。我的代码如下。

数据是使用查询中提到的条件从数据库绑定的。

  

使用以下函数将数据转换为html代码

 public string BindCard_AssetReport(string main_group, string sub_group, string deptmnt, string empId)
{
    string ddlGroup = DDLAssetGroup.SelectedItem.Text;
    string ddlSubGrp = DDLAssetSubGroup.SelectedItem.Text;
    string ddlDept = DDLDepartment.SelectedItem.Text;
    string ddlUserCode = DDLUser.SelectedItem.Value;


    DataTable dtAsset = getAssetReportList(ddlGroup, ddlSubGrp, ddlDept, ddlUserCode, Session["firmcode"].ToString(), Session["ConnStr"].ToString());

    string str =  "<div class='col-md-12'>";       
    for (int i = 0; i < dtAsset.Rows.Count; i++)
    {
        str = str + "<div class='card-deck'>";
        str = str + "<div class='col-md-3'>";
        str = str + "<div class='card text-white bg-danger'  >";
        str = str + "<div class='card-header text-center'>" + "Code : ".ToString() + dtAsset.Rows[i].ItemArray[0].ToString() + " </div> ";
        str = str + " <div class='card-body'>";
        str = str + "<h5 class='card-title text-center'>" + "Name : ".ToString() + dtAsset.Rows[i].ItemArray[1].ToString() + " </h5> ";
        str = str + "<ul class='list-group list-group-flush'>";
        str = str + "<li class='list-group-item'>" + "Group : ".ToString() + dtAsset.Rows[i].ItemArray[2].ToString() + "</li>";
        str = str + "<li class='list-group-item'>" + "Sub-Group : ".ToString() + dtAsset.Rows[i].ItemArray[3].ToString() + "</li>";
        str = str + "<li class='list-group-item'>" + "Department : ".ToString() + dtAsset.Rows[i].ItemArray[4].ToString() + "</li>";
        str = str + "<li class='list-group-item'>" + "Model : ".ToString() + dtAsset.Rows[i].ItemArray[5].ToString() + "</li>";
        str = str + "</ul>";
        str = str + "</div>";
        str = str + "</div>";
        str = str + "</div>";
        str = str + "</div>";

    }      
    str = str + "</div>";

    return str;
}
  

从数据库获取数据

 public DataTable getAssetReportList( string main_grp,string sub_grp,string dept,string empcode, string companyid, string cnn)
{

    StringBuilder str = new StringBuilder();
    str.Append("select code,name,main_group,sub_group,department,model from master_asset");
    //,serial_no,registration_no,renewal_date,amc_status,amc_details,amc_expiry
    str.Append(" where  code= '" + empcode + "' and main_group='"+main_grp+"' and sub_group = '"+sub_grp+"'and department ='"+dept+"' and  companyid = " + companyid);
    return Datalayer.GetDatatable(str.ToString(), cnn);
}
  

报告生成按钮

 protected void btn_save_Click(object sender, EventArgs e)
{
    string ddlGroup = DDLAssetGroup.SelectedItem.Text;
    string ddlSubGrp = DDLAssetSubGroup.SelectedItem.Text;
    string ddlDept = DDLDepartment.SelectedItem.Text;
    string ddlUserCode = DDLUser.SelectedItem.Value;

    div_list.InnerHtml = BindCard_AssetReport(ddlGroup, ddlSubGrp, ddlDept, ddlUserCode);
}
  

ASPX页面

<div class="row">
            <div class="col-md-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <asp:Label ID="lblasset" runat="server" Font-Bold="true" ForeColor="Red" Text="Asset Report"></asp:Label>
                    </div>
                    <div class="panel-body">

                        <div id="div_list" class="row" runat="server">
                        </div>

                    </div>
                </div>
            </div>

        </div>
  

屏幕截图已附加   Data binded to cards

我知道要使用databable导出到.xls文件,但是我想使用引导卡,现在无法导出它们。我只是编码方面的初学者,我需要获得的所有帮助。期待解决这个问题。

0 个答案:

没有答案