代码:

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. artTemplate-优秀的前端模板引擎

    artTemplate-优秀的前端模板引擎 1.html中引入artTemplate的js文件: <script type="text/javascript" src=&qu ...

  2. margin折叠及hasLayout && Block Formatting Contexts

    margin折叠的产生有几个条件: 这些margin都处于普通流中,并在同一个BFC中: 这些margin没有被非空内容.padding.border 或 clear 分隔开: 这些margin在垂直 ...

  3. Java性能调优:利用VisualVM进行性能分析

    JVisualVM 简介 VisualVM 是Netbeans的profile子项目,已在JDK6.0 update 7 中自带,能够监控线程,内存情况,查看方法的CPU时间和内存中的对 象,已被GC ...

  4. MySQL Optimization 优化原理

    MySQL Optimization 优化原理 MySQL逻辑架构 如果能在头脑中构建一幅MySQL各组件之间如何协同工作的架构图,有助于深入理解MySQL服务器.下图展示了MySQL的逻辑架构图. ...

  5. Cloudera Impala源码分析: SimpleScheduler调度策略详解包括作用、接口及实现等

    问题导读:1.Scheduler任务中Distributed Plan.Scan Range是什么?2.Scheduler基本接口有哪些?3.QuerySchedule这个类如何理解?4.Simple ...

  6. redis-手写redis切片和非切片连接池并注入springboot中

    spring-data整合了redispool, 并提供redisTemplate使用, 但有时需要用到shradedJedisPool, 就需要手动注入了 手写redispool并注入springb ...

  7. 不开vip会员照样看vip电影(亲测有效)

    此为临时链接,仅用于文章预览,将在短期内失效关闭 不开vip会员照样看vip电影(亲测有效) 2018-03-08 mr_lee Python达人课堂 刚刚测试,真实有效,颇不接待要分享了... 土豪 ...

  8. php的error_log()记录日志

    <?php date_default_timezone_set('PRC');//设置时区,否则会有警告 //把This s a error保存到/home/log-yyyy-MM-dd.txt ...

  9. 开发小技巧1——Logger

    开发小技巧1——Logger 在项目中加入静态Logger类,用于捕获并记录程序的进度.错误信息:   public static class Logger { public static void ...

  10. Nginx使用记录

    配置常见解释: ########### 每个指令必须有分号结束.################# #user administrator administrators; #配置用户或者组,默认为no ...