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

推荐订阅源

TaoSecurity Blog
TaoSecurity Blog
Jina AI
Jina AI
雷峰网
雷峰网
月光博客
月光博客
The GitHub Blog
The GitHub Blog
WordPress大学
WordPress大学
B
Blog RSS Feed
美团技术团队
C
CXSECURITY Database RSS Feed - CXSecurity.com
小众软件
小众软件
Security Latest
Security Latest
Microsoft Azure Blog
Microsoft Azure Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cybersecurity and Infrastructure Security Agency CISA
Last Week in AI
Last Week in AI
A
Arctic Wolf
Latest news
Latest news
Attack and Defense Labs
Attack and Defense Labs
I
Intezer
F
Fortinet All Blogs
罗磊的独立博客
MongoDB | Blog
MongoDB | Blog
Webroot Blog
Webroot Blog
S
Secure Thoughts
Help Net Security
Help Net Security
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
V
Visual Studio Blog
P
Proofpoint News Feed
博客园 - 【当耐特】
P
Privacy International News Feed
V
Vulnerabilities – Threatpost
Stack Overflow Blog
Stack Overflow Blog
Know Your Adversary
Know Your Adversary
云风的 BLOG
云风的 BLOG
Hacker News: Ask HN
Hacker News: Ask HN
L
LINUX DO - 最新话题
H
Help Net Security
爱范儿
爱范儿
酷 壳 – CoolShell
酷 壳 – CoolShell
S
SegmentFault 最新的问题
Forbes - Security
Forbes - Security
T
Tailwind CSS Blog
量子位
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
Tenable Blog
Cloudbric
Cloudbric
N
News and Events Feed by Topic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Hugging Face - Blog
Hugging Face - Blog

博客园 - KenBlove

错误代码:0x800706BE 解决方法 泛微OA服务器更改IP地址后EMobile出现“调用远端服务器接口时发生错误(122)”的提示 HTTP 错误 404 - 文件或目录未找到 HTTP 错误 401.2 - 未经授权:访问由于服务器配置被拒绝。 优雅还不够,简洁才高效!——用NValidator一句话搞定客户端检测 一个仿PetShop的通用DBHelper类 纯CSS实现底部固定漂浮导航 Access和SQL server开启表间关系,并实现更新或删除母表数据自动更新或删除子表数据 来自微软关于异常处理的17条军规 一个简单的拖动层(兼容IE,FF) SQL Server Profiler过滤本机信息的办法 "The state information is invalid for this page and might be corrupted"错误的一个解决办法 SQL回滚Transaction来调试SQL语句 SQL找出和删除一个表的重复记录 SQL常用判断检测语句 SQL把ID相同的记录合并成同一条记录 从丑陋到优雅,让代码越变越美续集之服务器端数据校验 关于FireFox记住密码后出现的bug 关于Iframe在IE6下不显示的bug 从丑陋到优雅,让代码越变越美(客户端检测方法思考)
MyXls初级教程
KenBlove · 2009-09-07 · via 博客园 - KenBlove

这些天使用MyXls导出Excel报表(因为Apose.Cells要收费)。感觉MyXls虽然功能远没有Cells强大,但是胜在开源、免费而且性能稳定可靠。用作出一般情况下的报表。足矣!

记下几个初级使用方法,希望能够给初入门的人一点帮助:

1.创建一个Excel文档:

Code
XlsDocument xls = new XlsDocument();

2.创建一个WorkSheet:

Code
Worksheet ws = xls.Workbook.Worksheets.Add("WorkSheet1");

3.指定列格式:

Code
ColumnInfo colInfo = new ColumnInfo(xls, ws);
colInfo.ColumnIndexStart 
= 0;
colInfo.ColumnIndexEnd 
= 17;
colInfo.Width 
= 15 * 256;
ws.AddColumnInfo(colInfo);

列格式必须每次都要重新定义,一个列格式不能重复使用。

4.指定单元格样式:

Code
XF xf = xls.NewXF();
xf.HorizontalAlignment 
= HorizontalAlignments.Centered;
xf.VerticalAlignment 
= VerticalAlignments.Centered;
xf.Pattern 
= 1;
xf.PatternColor 
= Colors.Default30;
xf.UseBorder 
= true;
xf.TopLineStyle 
= 1;
xf.TopLineColor 
= Colors.Black;
xf.BottomLineStyle 
= 1;
xf.BottomLineColor 
= Colors.Black;
xf.LeftLineStyle 
= 1;
xf.LeftLineColor 
= Colors.Black;
xf.RightLineStyle 
= 1;
xf.RightLineColor 
= Colors.Black;
xf.Font.Bold 
= true;
xf.Font.Height 
= 11 * 20;
xf.Font.ColorIndex 
= 1;

5.给单元格赋值:

Code
ws.Cells.Add(23"金额(万元)", xf);

6.合并单元格:

Code
ws.Cells.Merge(1222);
//或者
ws.AddMergeArea(new MergeArea(1211));

7.MyXls合并单元格有个bug,就是合并后只是第一个单元格有样式,其余的样式丢失。所以写了个函数来合并:

Code
MergeRegion(ref ws, xf, "机构"1121);public void MergeRegion(ref Worksheet ws, XF xf, string title, int startRow, int startCol, int endRow, int endCol)
{
      
for (int i = startCol; i <= endCol; i++)
      {
            
for (int j = startRow; j <= endRow; j++)
            {
                ws.Cells.Add(j, i, title, xf);
            }
      }
      ws.Cells.Merge(startRow, endRow, startCol, endCol);
}

虽然效率不怎么样,但是对于出Excel报表,还OK。

8.指定单元格格式:

Code
cell.Format = StandardFormats.Decimal_1;

具体更多请参考源代码的StandardFormats类。

9.保存或者发送Excel:

Code
xls.Send();
//或者
xls.Save();