欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

拼接的字符串导入EXCEL

程序员文章站 2022-07-04 12:10:03
stringbuilder sb = new stringbuilder();           ...

stringbuilder sb = new stringbuilder();
            sb.appendline("<table><tr><th>序号</th><th>批单号</th><th>保单号</th><th>被保险人</th><th>保全项目</th><th>退费金额</th><th>保全操作日期</th><th>经办人</th></tr>");
            int i = 1;
            string str = "abc";
            string str1 = "wanglei";
            string str2 = "aaa";
            string time1 = datetime.now.tostring();
            sb.appendline("<tr><td>1</td><td style=\"vnd.ms-excel.numberformat:@\">" + 243123 + "</td><td style=\"vnd.ms-excel.numberformat:@\">" + str + "</td><td>" + str1 + "</td><td>" + str2 + "</td><td>"  + "</td><td>" + time1 + "</td><td>" + str  + "</td></tr>");
            //foreach (billchange change in list)
            //{
            //    sb.appendline("<tr><td>" + (i++).tostring() + "</td><td style=\"vnd.ms-excel.numberformat:@\">" + change.changebillcode + "</td><td style=\"vnd.ms-excel.numberformat:@\">" + change.billcode + "</td><td>" + change.billholder + "</td><td>" + getchangetypestring(change.changetype) + "</td><td>" + (change.returnfee > 0 ? change.returnfee.tostring() : "") + "</td><td>" + change.createdatetime.tostring("yyyy-mm-dd") + "</td><td>" + change.creatorname + "</td></tr>");
            //}
            sb.insert(0, "<html><head><meta content='text/html; charset=utf-8' http-equiv='content-type' /></head><body><table border=1>");
            sb.appendline("</table></body></html>");
            response.clear();
            response.buffer = true;
            response.charset = "utf-8";
            response.appendheader("content-disposition", "attachment;filename=\"" + server.urlencode("保单变更信息.xls") + "\"");
            response.contentencoding = encoding.utf8;
            response.contenttype = "application/ms-excel";
            response.write(sb.tostring());
            response.end();

 


摘自 wanglei_smartfish的专栏