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. ...
随机推荐
- C++ 文件hash值 BT种子的hash值
这个两个东东,是我在网上找到的.小小的修改了一下方便大家使用. 一个是 获取文件哈希值的,另外一个是获取torrent文件磁力链接的哈希值. 整理好的类下载地址: 文件hash值: http://pa ...
- Java SE 17 新增特性
Java SE 17 新增特性 作者:Grey 原文地址:Java SE 17 新增特性 源码 源仓库: Github:java_new_features 镜像仓库: GitCode:java_new ...
- Python小游戏——外星人入侵(保姆级教程)第一章 05重构模块game_functions
系列文章目录 第一章:武装飞船 05:重构:模块game_functions 一.重构 在大型项目中,经常需要在添加新代码前重构既有代码.重构旨在简化既有代码的结构,使其更容易扩展.在本节中,我们将创 ...
- P4675 [BalticOI 2016 day1]Park (并查集)
题面 在 Byteland 的首都,有一个以围墙包裹的矩形公园,其中以圆形表示游客和树. 公园里有四个入口,分别在四个角落( 1 , 2 , 3 , 4 1, 2, 3, 4 1,2,3,4 分别对应 ...
- 无密码正向直连内网linux目标机复现
无密码正向直连内网linux目标机复现 文章来自sxf大佬klion https://mp.weixin.qq.com/s/GPPvci8qKuvc5d3Q7Cer7Q 场景说明 前期通过一些 Rce ...
- 学习ASP.NET Core Blazor编程系列二——第一个Blazor应用程序(上)
学习ASP.NET Core Blazor编程系列一--综述 一.概述 Blazor 是一个生成交互式客户端 Web UI 的框架: 使用 C# 代替 JavaScript 来创建信息丰富的交互式 U ...
- pathlib路径问题
下面是我的文件框架 app ------ file1---- .py1 file2---- .py2 config.py 我在config文件中设置了变量参数 BASE_DIR = pathlib.P ...
- Linux虚拟机破解密码步骤
Linux破解密码 重启系统 到达logo界面快速 按 e 编辑当前条目 将光标移至以 linux 开头的行,此为内核命令行 在UTF-8(RHEL7):ro(RHEL8)后添加 rd.break ( ...
- v-if和v-for的优先级是什么?
一.作用 v-if 指令用于条件性地渲染一块内容.这块内容只会在指令的表达式返回 true值的时候被渲染 v-for 指令基于一个数组来渲染一个列表.v-for 指令需要使用 item in item ...
- 使用『jQuery』『原生js』制作一个导航栏动效 —— { }
效果 HTML部分 <body> <nav> <div id="nav1">导航1</div> <div id="n ...