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

推荐订阅源

Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
月光博客
月光博客
MyScale Blog
MyScale Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
爱范儿
爱范儿
P
Proofpoint News Feed
人人都是产品经理
人人都是产品经理
Last Week in AI
Last Week in AI
罗磊的独立博客
G
Google Developers Blog
Y
Y Combinator Blog
博客园 - 【当耐特】
WordPress大学
WordPress大学
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
J
Java Code Geeks
酷 壳 – CoolShell
酷 壳 – CoolShell
V
Visual Studio Blog
美团技术团队
宝玉的分享
宝玉的分享
Jina AI
Jina AI
小众软件
小众软件
T
Tailwind CSS Blog
A
About on SuperTechFans

博客园 - 星星博客园

关于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文件