惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
Help Net Security
Help Net Security
P
Privacy International News Feed
T
Threat Research - Cisco Blogs
C
Cisco Blogs
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
L
LINUX DO - 热门话题
Security Latest
Security Latest
A
Arctic Wolf
G
GRAHAM CLULEY
月光博客
月光博客
S
Securelist
D
Docker
J
Java Code Geeks
T
Troy Hunt's Blog
T
Tenable Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
SecWiki News
SecWiki News
S
Security @ Cisco Blogs
量子位
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
LINUX DO - 最新话题
Recent Commits to openclaw:main
Recent Commits to openclaw:main
aimingoo的专栏
aimingoo的专栏
博客园 - 【当耐特】
H
Heimdal Security Blog
The Hacker News
The Hacker News
博客园 - 三生石上(FineUI控件)
Application and Cybersecurity Blog
Application and Cybersecurity Blog
N
Netflix TechBlog - Medium
Vercel News
Vercel News
Forbes - Security
Forbes - Security
B
Blog RSS Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
B
Blog
MongoDB | Blog
MongoDB | Blog
博客园 - 聂微东
Google DeepMind News
Google DeepMind News
S
Secure Thoughts
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Check Point Blog
云风的 BLOG
云风的 BLOG
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
The Blog of Author Tim Ferriss
L
Lohrmann on Cybersecurity
F
Full Disclosure
D
Darknet – Hacking Tools, Hacker News & Cyber Security
P
Proofpoint News Feed

博客园 - 星星博客园

关于win10打开Word文件提示“转换文件”,选择文件类型的问题解决方式 关于安装R语言的Rattle报错问题的解决方式 office安装错误,报1603 apple mobile device recovery mode 问题解决 关于informix中判断字母是否为汉字的一点技巧 使用Hibernet开发informix数据库程序小结 etc的默认级别 MySQL关于TYPE和ENGIN的一点问题 转两篇关于JVM参数调优 SQL与NoSQL的一些内容汇总 informix 临时空间 Informix 生成随机数 研究Mybatis的Jpetshop-系统搭建(一) 创建一个Jetty的Server 先写一点informix的 文件 "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\mastlog.ldf " 已压缩,但未驻留在只读数据库或文件组中。必须将此文件解压缩。【转】 - 星星博客园 Weblogic常用监控指标(转) BEA WebLogic平台下J2EE调优攻略【转】 关于Session问题
导出Excel(脱离Office环境)
星星博客园 · 2011-04-29 · via 博客园 - 星星博客园

1、引用MyXls.SL2.dll文件

2、代码示例

  public void Out2Excel(string filename)
        {
            
//生成Excel开始
            XlsDocument xls = new XlsDocument();//创建空xls文档
            xls.FileName = System.IO.Directory.GetCurrentDirectory() + "\\" + filename + ".xls";//保存路径,如果直接发送到客户端的话只需要名称 生成名称
            Worksheet sheet = xls.Workbook.Worksheets.AddNamed(filename); //创建一个工作页为Dome             
            
//设置文档列属性 
            ColumnInfo cinfo = new ColumnInfo(xls, sheet);//设置xls文档的指定工作页的列属性
            cinfo.Collapsed = true;
            
//设置列的范围 如 0列-10列
            cinfo.ColumnIndexStart = 0;//列开始
            cinfo.ColumnIndexEnd = (ushort)lsvContent.Items.Count;//列结束
            cinfo.Collapsed = true;
            cinfo.Width 
= 120 * 60;//列宽度
            sheet.AddColumnInfo(cinfo);
            
//设置文档列属性结束
            
//设置指定工作页跨行跨列
            MergeArea ma = new MergeArea(1114);//从第1行跨到第二行,从第一列跨到第4列
            sheet.AddMergeArea(ma);
            
//设置指定工作页跨行跨列结束
            
//创建列样式创建列时引用
            XF cellXF = xls.NewXF();
            cellXF.VerticalAlignment 
= VerticalAlignments.Centered;
            cellXF.HorizontalAlignment 
= HorizontalAlignments.Centered;
            cellXF.Font.Height 
= 24 * 12;
            cellXF.Font.Bold 
= true;
            cellXF.Pattern 
= 1;//设定单元格填充风格。如果设定为0,则是纯色填充
            cellXF.PatternBackgroundColor = Colors.Red;//填充的背景底色
            cellXF.PatternColor = Colors.Red;//设定填充线条的颜色
            
//创建列样式结束
            
//创建列
            Cells cells = sheet.Cells; //获得指定工作页列集合
            
//列操作基本
            Cell cell = cells.Add(11"对账文件"+filename, cellXF);//添加标题列返回一个列 参数:行 列 名称 样式对象
            
//设置XY居中
            cell.HorizontalAlignment = HorizontalAlignments.Centered;
            cell.VerticalAlignment 
= VerticalAlignments.Centered;
            
//设置字体
            cell.Font.Bold = true;//设置粗体
            cell.Font.ColorIndex = 0;//设置颜色码           
            cell.Font.FontFamily = FontFamilies.Roman;//设置字体 默认为宋体               
            
//创建列结束 
            
//创建列表头
            Cell title = cells.Add(21"对账日期");
            title 
= cells.Add(22"流水号");
            title 
= cells.Add(23"保单号");
            title 
= cells.Add(24"保费");           
            title.HorizontalAlignment 
= HorizontalAlignments.Right;
            title.VerticalAlignment 
= VerticalAlignments.Centered;
          
            
//创建模拟数据  
            
for (int i = 0; i < lsvContent.Items.Count; i++)
            {
                cells.Add(i 
+ 31, lsvContent.Items[i].SubItems[0].Text);//添加列,不设置列属性就不用返回列对象
                cells.Add(i + 32, lsvContent.Items[i].SubItems[1].Text);//添加列,不设置列属性就不用返回列对象
                cells.Add(i + 33, lsvContent.Items[i].SubItems[2].Text);//添加列,不设置列属性就不用返回列对象
                cells.Add(i + 34, lsvContent.Items[i].SubItems[3].Text);//添加列,不设置列属性就不用返回列对象
               
            }
//生成保存到服务器如果存在不会覆盖并且报异常所以先删除在保存新的
            File.Delete(System.IO.Directory.GetCurrentDirectory() + "\\" + filename + ".xls");//删除
            
//保存文档
            xls.Save();//保存到服务器
            
//xls.Send();//发送到客户端     
            System.Diagnostics.Process.Start(System.IO.Directory.GetCurrentDirectory() + "\\" + filename + ".xls");
        }

 引用文件lMyXls文件