Aspose.Cell篇章3,设置写入到Excel文件的各种样式及输出
Aspose.Cell的Style.Number设置全部设置
/// <summary>
/// 单元格样式编号
/// 0 General General
/// 1 Decimal 0
/// 2 Decimal 0.00
/// 3 Decimal #,##0
/// 4 Decimal #,##0.00
/// 5 Currency $#,##0;$-#,##0
/// 6 Currency $#,##0;[Red]$-#,##0
/// 7 Currency $#,##0.00;$-#,##0.00
/// 8 Currency $#,##0.00;[Red]$-#,##0.00
/// 9 Percentage 0%
/// 10 Percentage 0.00%
/// 11 Scientific 0.00E+00
/// 12 Fraction # ?/?
/// 13 Fraction # ??/??
/// 14 Date m/d/yy
/// 15 Date d-mmm-yy
/// 16 Date d-mmm
/// 17 Date mmm-yy
/// 18 Time h:mm AM/PM
/// 19 Time h:mm:ss AM/PM
/// 20 Time h:mm
/// 21 Time h:mm:ss
/// 22 Time m/d/yy h:mm
/// 37 Currency #,##0;-#,##0
/// 38 Currency #,##0;[Red]-#,##0
/// 39 Currency #,##0.00;-#,##0.00
/// 40 Currency #,##0.00;[Red]-#,##0.00
/// 41 Accounting _ * #,##0_ ;_ * -#,##0_ ;_ * "-"_ ;_ @_
/// 42 Accounting _ $* #,##0_ ;_ $* -#,##0_ ;_ $* "-"_ ;_ @_
/// 43 Accounting _ * #,##0.00_ ;_ * -#,##0.00_ ;_ * "-"??_ ;_ @_
/// 44 Accounting _ $* #,##0.00_ ;_ $* -#,##0.00_ ;_ $* "-"??_ ;_ @_
/// 45 Time mm:ss
/// 46 Time [h]:mm:ss
/// 47 Time mm:ss.0
/// 48 Scientific ##0.0E+00
/// 49 Text @
/// </summary>
举一个动态设定单元格数字样式的例子,通过GetStyle()方法获取单元格样式,然后,设置Number样式
Aspose.Cells.Style style = ws.Cells[i,j].GetStyle();//ws为WorkSheet实例
style.Number = 10 //这里设置为百分比
ws.Cells[i,j].SetStyle(style)
还可以设置整个Workbook的样式public Style GetStyle(Worksheet ws,SheetTemplateColumnEntity column)
{
Aspose.Cells.Style style = ws.Workbook.Styles[ws.Workbook.Styles.Add()];
style.Font.IsBold = true;
style.Font.Size = 12;
System.Drawing.Color bcolor = System.Drawing.ColorTranslator.FromHtml("");
style.ForegroundColor = bcolor;//背景色
System.Drawing.Color fcolor = System.Drawing.ColorTranslator.FromHtml("");
style.Font.Color = fcolor;
style.Font.Name = "微软雅黑";
style.IndentLevel = 2;//缩进量
style.Number = 10;
style.HorizontalAlignment = (TextAlignmentType)(Enum.Parse(typeof(TextAlignmentType),""));
style.VerticalAlignment = (TextAlignmentType)(Enum.Parse(typeof(TextAlignmentType),""));
style.IsLocked = true;
style.IsTextWrapped = false ; //获取或设置自动换行
style.Borders.SetColor(System.Drawing.Color.Black);//边框颜色
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.Pattern = BackgroundType.Solid;
return style;
}
//锁定单元格,style.IsLocked使用的时候,锁定的设置为true,不锁定的设置为false。
ws.Protect(ProtectType.All,"654321",null)--设置解锁锁定后,需要设置sheet保护,才能生效
//设置折叠行
ws.Cells.GroupRow(startrow,endrow,false);
//设置折叠行后,需要设置SummaryRowBelow来使,折叠符号变正
ws.Outline.SummaryRowBelow = false;
ws.FreezePanes(startrow,startcol,rowcount,colcount);//冻结行列
ws.Protection.AllowSelectingLockedCell = false;
ws.Protection.AllowInsertingRow = true;
ws.Protection.AllowDeletingRow = true;
ws.Protection.AllowFormattingColumn = true;
ws.Protection.AllowFormattingRow = true;
ws.IsOutlineShown = true;//折线显示
wb.CalculateFormula();//刷新公式
添加一种新的输出方式,直接返回给网页
XlsSaveOptions saveOptions = new XlsSaveOptions(SaveFormat.Xlsm);
string excelname = Year + "年" + entity.FullName + "管理利润导入报表.Xlsm";
if (HttpContext.Current.Request.UserAgent.ToLower().ToString().IndexOf("firefox") < 0)
{
wb.Save(System.Web.HttpContext.Current.Response, HttpUtility.UrlEncode(excelname, System.Text.Encoding.UTF8), ContentDisposition.Attachment, saveOptions);
}
else
{
wb.Save(System.Web.HttpContext.Current.Response, excelname, ContentDisposition.Attachment, saveOptions);
}
Aspose.Cell篇章3,设置写入到Excel文件的各种样式及输出的更多相关文章
- 使用Aspose.Cell控件实现多个Excel文件的合并
之前有写过多篇关于使用Apose.Cell控件制作自定义模板报表和通用的导出Excel表格数据的操作,对这个控件的功能还是比较满意,而且也比较便利.忽然有一天,一个朋友说:你已经有生成基于自定义模板报 ...
- 把读取sql的结果写入到excel文件
1.利用pandas模块 # encoding: utf-8 import time import pandas as pd import pymysql def getrel(sql): ''' 连 ...
- Aspose.cell.dll的使用,导excel表
using System; using System.Web; using EF; using Newtonsoft.Json; using System.Collections.Generic; u ...
- 使用Aspose.Cell控件实现Excel高难度报表的生成(三)
在之前几篇文章中,介绍了关于Apsose.cell这个强大的Excel操作控件的使用,相关文章如下: 使用Aspose.Cell控件实现Excel高难度报表的生成(一) 使用Aspose.Cell控件 ...
- 利用Aspose.Word控件和Aspose.Cell控件,实现Word文档和Excel文档的模板化导出
我们知道,一般都导出的Word文档或者Excel文档,基本上分为两类,一类是动态生成全部文档的内容方式,一种是基于固定模板化的内容输出,后者在很多场合用的比较多,这也是企业报表规范化的一个体现. 我的 ...
- 使用Aspose.Cell控件实现Excel高难度报表的生成(一)
时光飞逝,生活.工作.业余研究总是在不停忙碌着,转眼快到月底,该月的博客文章任务未完,停顿回忆一下,总结一些经验以及好的东西出来,大家一起分享一下.本文章主要介绍报表的生成,基于Aspose.Cell ...
- (转)使用Aspose.Cell控件实现Excel高难度报表的生成(一)
本文章主要介绍报表的生成,基于Aspose.Cell控件的报表生成.谈到报表,估计大家都有所领悟以及个人的理解,总的来说,一般的报表生成,基本上是基于以下几种方式:一种是基于微软Excel内置的引擎来 ...
- C# Aspose.Cells方式导入Excel文件
读取Excel 类 我返回的是DataTable 类型 也可以返回DataSet类型 public class XlsFileHelper { public DataTable ImportExcel ...
- Python学习笔记_从CSV读取数据写入Excel文件中
本示例特点: 1.读取CSV,写入Excel 2.读取CSV里具体行.具体列,具体行列的值 一.系统环境 1. OS:Win10 64位英文版 2. Python 3.7 3. 使用第三方库:csv. ...
随机推荐
- Selenium 4 有哪些不一样?
转载请注明出处️ 作者:测试蔡坨坨 原文链接:caituotuo.top/d59b986c.html 你好,我是测试蔡坨坨. 众所周知,Selenium在2021年10月13号发布了Selenium4 ...
- NC202475 树上子链
题目链接 题目 题目描述 给定一棵树 T ,树 T 上每个点都有一个权值. 定义一颗树的子链的大小为:这个子链上所有结点的权值和 . 请在树 T 中找出一条最大的子链并输出. 输入描述 第一行输入一个 ...
- Java中数组
数组的定义格式: 1: 数据类型[] 数组名 2: 数据类型 数组名 动态初始化: 初始化的时候 系统会默认给数组赋值 数据类型[] 变量名 = new 数据类型[数组长度] int[] arr = ...
- class 中的 构造方法、static代码块、私有/公有/静态/实例属性、继承 ( extends、constructor、super()、static、super.prop、#prop、get、set )
part 1 /** * << class 中的 static 代码块与 super.prop 的使用 * * - ...
- KingbaseES R3 集群主库归档失败案例
案例说明: 本案例用于KingbaseES R3集群归档进程归档日志失败的处理,对于一线的生产环境具有 一定的参考意义. 数据库版本: TEST=# select version(); VERSION ...
- K8S_常用指令
kubectl get 显示一个或更多resources资源 # 查看集群状态 kubectl get cs # 查看集群节点信息 kubectl get nodes # 查看集群命名空间 kubec ...
- C++ 二级指针与 const 关键字
可用七种不同的方式将 const 关键字用于二级指针,如下所示: //方式一:所指一级指针指向的数据为常量,以下几种为等效表示 const int ** pptc; //方式一 int const * ...
- PHP函数小工具
PHP检测IP是否内网地址.保留地址 /** * @param string $ip 被检测的IP * @return bool 是否内网或者保留IP */ public function isInt ...
- kali2020.1修改root密码,以最高权限登录系统
普通用户权限登录系统 sodu su切换为root权限 passwd root 按提示输入密码 再次输入密码 更新密码 右上角点切换用户 root/xxxx 更改成功,下面公布操图片
- 在Ubuntu上安装Odoo时遇到的问题
这两天开始看<Odoo快速入门与实践 Python开发ERP指南>(刘金亮 2019年5月第1版 机械工业出版社).试着在Ubuntu上安装Odoo,遇到很多问题,通过在网上查找,都已解 ...