代码:

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. Unity 使用有限状态机 完美还原 王者荣耀 虚拟摇杆

    Unity 使用有限状态机 完美还原 王者荣耀 虚拟摇杆 效果如图所示 摇杆的UI组成 如图所示 简单的可以认为摇杆由1.2.3贴图组成 为摇杆的底座 为摇杆的杆 为摇杆的指向 可以理解这就是街机上的 ...

  2. 【SQL查询】树结构查询

    格式:SELECT ... FROM + 表名 WHERE + 条件3 START WITH + 条件1 CONNECT BY PRIOR + 条件2条件1: 表示从哪个节点开始查找, 也就是通过条件 ...

  3. 2、如何解决xamarin没有相关教程的的指导贴

    本篇文章主要在于解决xamarin相关文档偏少的问题. 最终的代码并不重要.重要的还是那种处理的方式 授人以渔 群里有群友讨论说需要读取安卓的 充电电流.这样的问题实际上在原生java有一堆.但是到了 ...

  4. How React Works (一)首次渲染

    How React Works (一)首次渲染 一.前言 本文将会通过一个简单的例子,结合React源码(v 16.4.2)来说明 React 是如何工作的,并且帮助读者理解 ReactElement ...

  5. Java之IO(十)Reader和Writer

    转载请注明源出处:http://www.cnblogs.com/lighten/p/7071733.html 1.前言 之前的章节已经将Java8的io包中的字节流介绍完毕了.本章开始介绍Java的I ...

  6. python的字符串内建函数(方法)

    原本总结一下,后来发现这个里面讲的很全,可以点进去参考:http://www.runoob.com/python/python-strings.html

  7. 【jQuery源码】事件存储结构

    a. jQuery事件原型——Dean Edwards的跨浏览器AddEvent()设计 源码解读   重新梳理一下数据结构,使用一个例子 <input type="text" ...

  8. 【数组】Rotate Image

    题目: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwis ...

  9. Okhttp3上传多张图片同时传递参数

    之前上传图片都是直接将图片转化为io流传给服务器,没有用框架传图片. 最近做项目,打算换个方法上传图片. Android发展到现在,Okhttp显得越来越重要,所以,这次我选择用Okhttp上传图片. ...

  10. svn 服务器搭建 ,采用http的方式加密用户。

    1.1安装svn 1.环境 centos6.5 本地ip:192.168.2.154 2.安装 yum install subversion 查看版本 svnserve --version 3.创建版 ...