c# - 新手 ASP.net MVC 导出到 Excel
问题描述
我有一个应用程序,可以记录机构中的所有人。我有一个这样的页面
允许我这样做的功能是:
public void Test()
{
List<UserViewModel> emplist = db.users.Select(x => new UserViewModel
{
nom = x.nom,
prenom = x.prenom,
mobile = x.mobile,
fixe = x.fixe,
astreinte = x.astreinte
}).ToList();
ExcelPackage.LicenseContext = LicenseContext.Commercial;
ExcelPackage pck = new ExcelPackage();
ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Report");
我有所有数据,但它只是一行一行的,不是很清楚阅读或找到特定的东西。然后我有另一个按类别排序的页面:
一个类别的代码是:
<asp:repeater id="Repeater3" datasourceid="SqlDataSource3" runat="server">
<headertemplate>
<table id="users" class="display">
<thead>
<tr>
<th><b>Nom</b></th>
<th><b>Prenom</b></th>
<th><b>Fixe</b></th>
<th><b>Mobile</b></th>
<th><b>Astreinte</b></th>
</tr>
</thead>
<tbody>
</headertemplate>
<itemtemplate>
<tr>
<td> <%# Eval("nom") %> </td>
<td> <%# Eval("prenom") %> </td>
<td> <%# Eval("fixe") %> </td>
<td> <%# Eval("mobile") %> </td>
<td> <%# Eval("astreinte") %> </td>
</tr>
</itemtemplate>
<footertemplate>
</tbody>
</table>
</footertemplate>
</asp:repeater>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:HD_TracabiliteConnectionString %>"
SelectCommand="SELECT * FROM [users] INNER JOIN catuser ON users.user_num = catuser.user_num WHERE catuser.categorie = 3"
ProviderName="<%$ ConnectionStrings:HD_TracabiliteConnectionString.ProviderName %>"></asp:SqlDataSource>
</div>
我想要做的是通过转换这一行SelectCommand="SELECT * FROM [users] INNER JOIN catuser ON users.user_num = catuser.user_num WHERE catuser.categorie = 3"
并将其集成到我的函数 Test() 按类别导出到 excel ?拜托,我真的需要帮助,求求你
解决方案
推荐阅读
- mongodb - 结果中的父子反转
- asp.net-core - SwaggerUI 中是否支持多个 oauth2 身份验证登录提供程序?
- maven - mulesoft maven 测试结果未公布
- javascript - React setState() 在多个智能组件中无法正常工作
- php - 在 Laravel 中查看如何对 URL 进行 json_decode
- http - HttpContext.Current.Request.Browser.MajorVersion 将 IE11 显示为 IE7
- html - 无法垂直居中 Bootstrap 3 媒体
- c++ - #SQLite This query statement does not work as I thought. What should I do
- android - Progress dialog in Multipart Upload Request
- java - Problem to insert new user to DB after checking if email exist sqlite