List集合 导出 Excel
public string CreateAdvExcel(IList<DocAdvInfo> lt)
{
StringBuilder builder = new StringBuilder();
Random rn = new Random();
string name = rn.Next(9999) + ".xls";
string path = Server.MapPath("\\Document\\" + name);
System.Reflection.PropertyInfo[] myPropertyInfo = lt.First().GetType().GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
int i = 0, j;
for (i = 0, j = myPropertyInfo.Length; i < j; i++)
{
System.Reflection.PropertyInfo pi = myPropertyInfo[i];
string headname = pi.Name;//单元格头部
builder.Append(headname);
builder.Append("\t");
}
builder.Append("\n");
foreach (DocAdvInfo t in lt)
{
if (lt == null)
{
continue;
}
for (i = 0, j = myPropertyInfo.Length; i < j; i++)
{
System.Reflection.PropertyInfo pi = myPropertyInfo[i];
string str = string.Format("{0}", pi.GetValue(t, null)).Replace("\n", "");
if (str == "")
{
builder.Append("\t");
}
else
{
builder.Append(str + "\t");//横向跳到另一个单元格
}
}
builder.Append("\n");//换行
}
StreamWriter sw = new StreamWriter(path, false, System.Text.Encoding.GetEncoding("GB2312"));
sw.Write(builder.ToString());//输出
sw.Flush();
sw.Close();
List集合 导出 Excel的更多相关文章
- 写一个通用的List集合导出excel的通用方法
前几天要做一个数据导出Excel 我就打算写一个通用的. 这样一来用的时候也方便,数据主要是通过Orm取的List.这样写一个通用的刚好. public static void ListToExcel ...
- Asp.net Core导出Excel
本篇文章是在MVC设计模式下,基于windows系统的Excel导出 1.前台的实现不用我多说了吧,加一个a标签链接地址跳到它所调用的方法里面,可以根据当前页面的查询条件去传值,从而查询出你想要的数据 ...
- 使用Magicodes.IE快速导出Excel
前言 总是有很多朋友咨询Magicodes.IE如何基于ASP.NET Core导出Excel,出于从框架的体验和易用性的角度,决定对Excel的导出进行独立封装,以便于大家更易于使用,开箱即用. 注 ...
- wpf 导出Excel Wpf Button 样式 wpf简单进度条 List泛型集合对象排序 C#集合
wpf 导出Excel 1 private void Button_Click_1(object sender, RoutedEventArgs e) 2 { 3 4 ExportDataGrid ...
- C#使用Aspose.Cells导出Excel简单实现
首先,需要添加引用Aspose.Cells.dll,官网下载地址:http://downloads.aspose.com/cells/net 将DataTable导出Xlsx格式的文件下载(网页输出) ...
- Java导出excel
一.介绍 常常有客户这样子要求:你要把我们的报表直接用Excel打开(电信系统.银行系统).或者是:我们已经习惯用Excel打印.这样在我们实际的开发中,很多时候需要实现导入.导出Excel的应用. ...
- NPOI操作EXCEL(四)——反射机制批量导出excel文件
前面我们已经实现了反射机制进行excel表格数据的解析,既然有上传就得有下载,我们再来写一个通用的导出方法,利用反射机制实现对系统所有数据列表的筛选结果导出excel功能. 我们来构想一下这样一个画面 ...
- js导出excel
function inportEx() { $("#btnEx").text("导出中..."); var fugNumber = "";/ ...
- MyXls导出Excel的各种设置
MyXls是一个操作Excel的开源类库,支持设置字体.列宽.行高(由BOSSMA实现).合并单元格.边框.背景颜色.数据类型.自动换行.对齐方式等,通过众多项目的使用表现,证明MyXls对于创建简单 ...
随机推荐
- ssh配置文件说明
配置“/etc/ssh/ssh_config”文件 “/etc/ssh/ssh_config” 文件是OpenSSH系统范围的配置文件,允许你通过设置不同的选项来改变客户端程序的运行方式.这个文件的每 ...
- ORACLE 创建作业JOB例子
--1.plsql中学习job --学习job --建表 create table test_job(para_date date); commit; insert into test ...
- 45. Scramble String
Scramble String Given a string s1, we may represent it as a binary tree by partitioning it to two no ...
- zmap使用笔记
zmap使用笔记 zmap, 一个网络端口开放性的快速扫描工具.至于这个工具的特色,配置参数,和比的工具的对比,不做介绍.只记录一下近期使用过程中,遇到的问题.软件版本:2.1.1 传言与现实 传言: ...
- java 获取classpath下文件多种方式
java 获取classpath下文件多种方式 一:properties下配置 在resources下定义server.properties register.jks.path=classpath\: ...
- openldap加密传输sssd
http://blog.father.gedow.net/2015/09/29/sssd-ldap-sudo/ yum -y install openldap-clients sssd authcon ...
- MySQL 常用命令(持续更新)
停止启动MySQL服务 停止:net stop mysql启动:net start mysql 查看正在运行的线程 SHOW PROCESSLIST SHOW FULL PROCESSLIST 杀死线 ...
- Microsoft source-code annotation language (SAL) 相关
More info see: https://msdn.microsoft.com/en-us/library/hh916383.aspx Simply stated, SAL is an inexp ...
- GTFS
Documentation The General Transit Feed Specification is documented on a Google Code site. Tables in ...
- java 标识符命名规则
标识符:就是给类,接口,方法,变量等起名字. 组成规则: A:英文字母大小写 B:数字字符 C:$和_ 注意事项: A:不能以数字开头 B:不能是Java中的关键字 C:Java语言严格区分大小写 包 ...