zoukankan      html  css  js  c++  java
  • 使用aspx 直接生成excel

    <%@ Page Language="C#" EnableEventValidation="false" ResponseEncoding="gb2312" ContentType="application/vnd.ms-excel" %>
    
    <%@ Import Namespace="IriskingAttend.Web" %>
    <%@ Import Namespace="System" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="application/vnd.ms-excel; charset=gb2312">
        <meta name="ProgId" content="Excel.Sheet">
        <meta name="Generator" content="Microsoft Excel 11">
    </head>
    <body>
        <% 
            Response.ContentType = "application/vnd.ms-excel"; Response.Charset = "utf-8"; Response.AddHeader("Content-Disposition", "inline; filename=" + "luanma.xls");
            Response.Write("<meta http-equiv=Content-Type content=text/html;charset=utf-8>");
        %>
        <div>
            <table x:str border="1" cellpadding="0" cellspacing="0" style='border-collapse: collapse;
                text-align: center; table-layout: fixed;  1000pt; height: 102px;'>
                <%
                    DateTime beginTime = Convert.ToDateTime(Request.QueryString["beginTime"]);
                    DateTime endTime = Convert.ToDateTime(Request.QueryString["endTime"]);
                    string departName = Request.QueryString["departName"];
                    int length = (int)endTime.AddDays(1).Subtract(beginTime).TotalDays;
                %>
                <tr>
                    <td colspan="<%=(length+15) %>" rowspan="2" align="center">
                        郭二庄月出勤明细报表 <span style='mso-spacerun: yes'> </span>
                        <%=beginTime.ToString("yyyy-MM-dd")%>
                        至
                        <%=endTime.ToString("yyyy-MM-dd")%> <span>部门:<%=departName %></span>
                    </td>
                </tr>
                <tr>
                    
                </tr>
                <tr>
                    <td rowspan="2" align="center">
                        姓名
                    </td>
                    <td rowspan="2" align="center">
                        考勤号
                    </td>
                    <td rowspan="2" align="center">
                        工数
                    </td>
                    <td colspan="2" class="style2" align="center">
                        其中
                    </td>
                    <% for (DateTime mindate = beginTime; mindate <= endTime; mindate = mindate.AddDays(1))
                       { %>
                    <td rowspan="2" class="style1" align="center">
                        <%=mindate.Day.ToString("d2")%>
                    </td>
                    <% } %>
                    <td colspan="3" class="style1" align="center">
                        对比数据
                    </td>
                    <td colspan="2" class="style2" align="center">
                        对比后
                    </td>
                    <td colspan="2" class="style2" align="center">
                        有工数
                    </td>
                    <td rowspan="2" class="style2" align="center">
                        有工数
                    </td>
                    <td colspan="2" class="style2" align="center">
                        其中:夜班
                    </td>
                </tr>
                <tr>
                    <td rowspan="1" align="center">
                        工数
                    </td>
                    <td rowspan="1" align="center">
                        工数
                    </td>
                    <td rowspan="1" align="center">
                        工数
                    </td>
                    <td rowspan="1" align="center">
                        异常
                    </td>
                    <td colspan="1" align="center">
                        异常
                    </td>
                    <td rowspan="1" align="center">
                        工数
                    </td>
                    <td rowspan="1" align="center">
                        工数
                    </td>
                    <td rowspan="1" align="center">
                        有资
                    </td>
                    <td colspan="1" align="center">
                        有资
                    </td>
                    <td rowspan="1" align="center">
                        井上工数
                    </td>
                    <td rowspan="1" align="center">
                        井下工数
                    </td>
                </tr>
                <%
                    for (int i = 0; i < DomainServiceIriskingAttend._monthAttendList.Count; i++)
                    {%>
                <tr height="19" style='height: 14.25pt'>
                    <td>
                        <%=DomainServiceIriskingAttend._monthAttendList[i].PersonName%>
                    </td>
                    <td>
                        <%=DomainServiceIriskingAttend._monthAttendList[i].AttendSn%>
                    </td>
                    <td>
                        <%=DomainServiceIriskingAttend._monthAttendList[i].WorkConut%>
                    </td>
                    <td>
                        <%=DomainServiceIriskingAttend._monthAttendList[i].WorkCount%>
                    </td>
                    <td>
                        <%=DomainServiceIriskingAttend._monthAttendList[i].WorkCount%>
                    </td>
                    <% for (int j = 0; j < length; j++)
                       { %>
                    <td>
                        <%= DomainServiceIriskingAttend._monthAttendList[i].DailySign[j]??"" %>
                    </td>
                    <% } %>
                    <td>
                        <%=DomainServiceIriskingAttend._monthAttendList[i].NormalWorkCount%>
                    </td>
                    <td>
                        <%=DomainServiceIriskingAttend._monthAttendList[i].Exception%>
                    </td>
                    <td>
                        <%=DomainServiceIriskingAttend._monthAttendList[i].LocationException%>
                    </td>
                    <td>
                        <%=DomainServiceIriskingAttend._monthAttendList[i].AfterOn%>
                    </td>
                    <td>
                        <%=DomainServiceIriskingAttend._monthAttendList[i].AfterIn%>
                    </td>
                    <td>
                        <%=DomainServiceIriskingAttend._monthAttendList[i].YouZi%>
                    </td>
                    <td>
                        <%=DomainServiceIriskingAttend._monthAttendList[i].YouZi%>
                    </td>
                    <td class="style2">
                        <%=DomainServiceIriskingAttend._monthAttendList[i].WorkCountable%>
                    </td>
                    <td class="style1">
                        <%=DomainServiceIriskingAttend._monthAttendList[i].NightOn%>
                    </td>
                    <td class="style1">
                        <%=DomainServiceIriskingAttend._monthAttendList[i].NightIn%>
                    </td>
                </tr>
                <%}%>
            </table>
        </div>
    </body>
    </html>
    

      //使用contentType 直接将输出格式改成application/vnd.ms-xls, 页面导向到这里直接下载。比较菜也是相对简单的一种方法

    //在IE下 中文文件名乱码问题解决

     string filename = "中文名称乱码.xls";
            // IE浏览器乱码问题,只能采用URLEncoder编码  
            filename = HttpUtility.UrlEncode(filename, Encoding.UTF8);
            Response.ContentType = "application/vnd.ms-excel"; Response.Charset = "utf-8"; Response.AddHeader("Content-Disposition", "inline; filename=" + filename);
    

      

  • 相关阅读:
    【Spring】每个程序员都使用Spring(四)——Aop+自定义注解做日志拦截
    倪光南:保护科技人员知识产权是提升企业创新的关键(柳传志,杨元庆没有投入资金和技术,却占了大量股份,在全世界都非常少见)
    凡是能导到线上的都已经尝试过了,现在转化用户成本非常高,到了强者恒强的时代
    MIPS 指令集将在近期开源,RISC-V 阵营慌吗?
    QmlWinExtras
    用css解决Unigui在IE系列浏览器中字体变小的问题(设置UniServeModule的customcss属性)
    uni-app
    .net core consul grpc--系统服务RPC实现通信(一)
    系统间通信——RPC架构设计
    程序是由数据结构属于静态的部分和算法的调用为动态部分构成
  • 原文地址:https://www.cnblogs.com/tony-brook/p/10519310.html
Copyright © 2011-2022 走看看