代码:

var execl_path = @"G:\zhyue\backup\项目修改-工作日常\2018-11-12 区域楼盘中心点和放大比例计算\a.xlsx";
Workbook wb = new Workbook();
Worksheet sheet = wb.Worksheets[]; //添加表头
sheet.Cells[, ].SetCell("区域", Color.FromArgb(, , ));
sheet.Cells[, ].SetCell("商圈", Color.FromArgb(, , ));
sheet.Cells[, ].SetCell("经度", Color.FromArgb(, , ));
sheet.Cells[, ].SetCell("纬度", Color.FromArgb(, , ));
sheet.Cells[, ].SetCell("实际距离", Color.FromArgb(, , ));
sheet.Cells[, ].SetCell("缩放比例", Color.FromArgb(, , ));
sheet.Cells[, ].SetCell("区域最大房源数", Color.FromArgb(, , ));
sheet.Cells[, ].SetCell("区域最小房源数", Color.FromArgb(, , ));
sheet.Cells[, ].SetCell("区域最大最小房源数比", Color.FromArgb(, , ));
sheet.Cells[, ].SetCell("执行级别(1-3)", Color.FromArgb(, , )); int row = ;//第几行
list_reach.ForEach(s =>
{
int i = ;
GetResult(s.SQID, out longitude, out latitude, out distance, out scale, out max_com_num, out min_com_num, out max_min_scale, ref i); sheet.Cells[row, ].SetCell(s.C_ReachName, Color.White);
sheet.Cells[row, ].SetCell(s.SQName, Color.White);
sheet.Cells[row, ].SetCell(longitude, Color.White);
sheet.Cells[row, ].SetCell(latitude, Color.White);
sheet.Cells[row, ].SetCell(distance, Color.White);
sheet.Cells[row, ].SetCell(scale, Color.White);
sheet.Cells[row, ].SetCell(max_com_num, Color.White);
sheet.Cells[row, ].SetCell(min_com_num, Color.White);
sheet.Cells[row, ].SetCell(max_min_scale, Color.White);
sheet.Cells[row, ].SetCell(i - , Color.White);
row++;
});
sheet.setColumnWithAuto();
wb.Save(execl_path);

引用扩展类

static class Cells1
{
/// <summary>
/// 设置cell的Value和Style
/// </summary>
/// <param name="cell"></param>
/// <param name="name"></param>
/// <param name="bgColor"></param>
public static void SetCell(this Cell cell, object name, Color bgColor)
{
cell.PutValue(name);//单元格值
Style style = new CellsFactory().CreateStyle();
style.ForegroundColor = bgColor;
style.Pattern = BackgroundType.Solid;//背景颜色不起作用,加入该行代码
style.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线
style.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线
style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
style.HorizontalAlignment = TextAlignmentType.Center;
style.VerticalAlignment = TextAlignmentType.Center;
cell.SetStyle(style);
} /// <summary>
/// 设置表页的列宽度自适应
/// </summary>
/// <param name="sheet">worksheet对象</param>
public static void setColumnWithAuto(this Worksheet sheet)
{
Cells cells = sheet.Cells;
int columnCount = cells.MaxColumn; //获取表页的最大列数
int rowCount = cells.MaxRow; //获取表页的最大行数 for (int col = ; col <= columnCount; col++)
{
sheet.AutoFitColumn(col, , rowCount);
}
for (int col = ; col <= columnCount; col++)
{
cells.SetColumnWidthPixel(col, cells.GetColumnWidthPixel(col) + );
}
}
}

Aspose.cells常用用法1的更多相关文章

  1. Aspose.Cells 基础用法

    最近使用Aspose.Cells做Excel,在怎么添加批注和添加内部导航链接上耗费了一些时间,最后在官网上找到相关用法,记录一下. 代码不用过多介绍,看看即可明白. 测试代码下载 Workbook ...

  2. Aspose.Cells.dll的用法

    public void OutExcel() { #region WorkbookDesigner designer = new WorkbookDesigner(); Worksheet sheet ...

  3. 常用类-Excel-使用Aspose.Cells插件

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Xm ...

  4. NPOI、MyXls、Aspose.Cells 导入导出Excel(转)

    Excel导入及导出问题产生: 从接触.net到现在一直在维护一个DataTable导s出到Excel的类,时不时还会维护一个导入类.以下是时不时就会出现的问题: 导出问题: 如果是asp.net,你 ...

  5. 对Aspose.Cells Excel文件操作的扩展

    工作中对Excel操作的需求很是常见,今天其他项目组的同事在进行Excel数据导入时,使用Aspose.Cells Excel 遇到了些问题. 刚好闲来不忙,回想自己用过的Excel文件操作,有NPO ...

  6. C#使用Aspose.Cells导出Excel简单实现

    首先,需要添加引用Aspose.Cells.dll,官网下载地址:http://downloads.aspose.com/cells/net 将DataTable导出Xlsx格式的文件下载(网页输出) ...

  7. Aspose.Cells导出Excel(2)

    DataTable dtTitle = ds.Tables[]; DataTable dtDetail = ds.Tables[]; int columns = dtTitle.Columns.Cou ...

  8. Aspose.Cells导出Excel(1)

    利用Aspose.Cells导出excel 注意的问题 1.DataTable的处理 2.进行编码,便于中文名文件下载 3.别忘了Aspose.Cells.dll(可以自己在网上搜索) public ...

  9. 使用Aspose.Cells读取Excel

      最新更新请访问: http://denghejun.github.io Aspose.Cells读取Excel非常方便,以下是一个简单的实现读取和导出Excel的操作类: 以下是Aspose.Ce ...

随机推荐

  1. 服务器集群的session管理

    应用服务器的高可用架构设计主要基于服务无状态这一特性,但是事实上,业务总是有状态的,单机情况下,Session可由部署在服务器上的web容器(如Jboss)管理.在使用负载均衡的集群环境中,由于负载均 ...

  2. JS优先队列排序。出队时,先找出优先级最高的元素,再按照先进先出出队。

    JS优先队列排序.出队时,先找出优先级最高的元素,再按照先进先出出队. /* * 优先队列 * 出队时,先找出优先级最高的元素,再按照先进先出出队. * */ function Queue(){ th ...

  3. 【转】MySQL下载安装验证

    MySQL官网下载路径:https://dev.mysql.com/downloads/mysql/ MySQL安装步骤:转自博主 Smile_Coding 博文:https://www.cnblog ...

  4. (转)Python科学计算之Pandas详解,pythonpandas

    https://www.cnblogs.com/linux-wangkun/p/5903380.html-------pandas 学习(1): pandas 数据结构之Series https:// ...

  5. (转) mysqldumpslow使用说明总结

    原文:http://blog.csdn.net/langkeziju/article/details/49301993 mysqldumpslow使用说明mysqldumpslow --helpUsa ...

  6. Zookeeper--0100--简介说明

    1.1-Zookeeper简介 什么是Zookeeper? Zookeeper是一个高效的分布式协调服务,它暴露了一些公共服务,比如命名/配置/管理/同步控制/群组服务等.我们可以使用ZK来实现比如达 ...

  7. redis配置详细解析

    # redis 配置文件示例 # 当你需要为某个配置项指定内存大小的时候,必须要带上单位, # 通常的格式就是 1k 5gb 4m 等: # # 1k => 1000 bytes # 1kb = ...

  8. javascript闭包获取table中tr的索引 分类: JavaScript 2015-05-04 15:10 793人阅读 评论(0) 收藏

    使用javascript闭包获取table标签中tr的索引 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN& ...

  9. 【数组】Next Permutation

    题目: Implement next permutation, which rearranges numbers into the lexicographically next greater per ...

  10. Git 命令操作记录

    1.安装完git软件之后(win系统的) 1)配置用户名密码: 设置本地机器默认commit的昵称与Email. 请使用有意义的名字与email. git config --global user.n ...