C# Aspose.Cells 如何设置单元格样式
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Adding a new worksheet to the Workbook object
int i = workbook.Worksheets.Add();
//Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[i];
//Adding the current system date to "A1" cell
worksheet.Cells["A1"].PutValue(DateTime.Now);
//Getting the Style of the A1 Cell
Style style = worksheet.Cells["A1"].GetStyle();
//Setting the display format to number 15 to show date as "d-mmm-yy"
style.Number = ;
//Applying the style to the A1 cell
worksheet.Cells["A1"].SetStyle(style);
//Adding a numeric value to "A2" cell
worksheet.Cells["A2"].PutValue();
//Getting the Style of the A2 Cell
style = worksheet.Cells["A2"].GetStyle();
//Setting the display format to number 9 to show value as percentage
style.Number = ;
//Applying the style to the A2 cell
worksheet.Cells["A2"].SetStyle(style);
//Adding a numeric value to "A3" cell
worksheet.Cells["A3"].PutValue();
//Getting the Style of the A3 Cell
style = worksheet.Cells["A3"].GetStyle();
//Setting the display format to number 6 to show value as currency
style.Number = ;
//Applying the style to the A3 cell
worksheet.Cells["A3"].SetStyle(style);
//Saving the Excel file
workbook.Save("C:\\book1.xls", SaveFormat.Excel97To2003);
当然开发人员还可以为单元格设置自定义显示样式,下面的代码就怎么设置单元格自定义显示样式做举例:
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Adding a new worksheet to the Excel object
int i = workbook.Worksheets.Add();
//Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[i];
//Adding the current system date to "A1" cell
worksheet.Cells["A1"].PutValue(DateTime.Now);
//Getting the style of A1 cell
Style style = worksheet.Cells["A1"].GetStyle();
//Setting the custom display format to show date as "d-mmm-yy"
style.Custom = "d-mmm-yy";
//Applying the style to A1 cell
worksheet.Cells["A1"].SetStyle(style);
//Adding a numeric value to "A2" cell
worksheet.Cells["A2"].PutValue();
//Getting the style of A2 cell
style = worksheet.Cells["A2"].GetStyle();
//Setting the custom display format to show value as percentage
style.Custom = "0.0%";
//Applying the style to A2 cell
worksheet.Cells["A2"].SetStyle(style);
//Adding a numeric value to "A3" cell
worksheet.Cells["A3"].PutValue();
//Getting the style of A3 cell
style = worksheet.Cells["A3"].GetStyle();
//Setting the custom display format to show value as currency
style.Custom = "£#,##0;[Red]$-#,##0";
//Applying the style to A3 cell
worksheet.Cells["A3"].SetStyle(style);
//Saving the Excel file
workbook.Save("C:\\book1.xls", SaveFormat.Excel97To2003);
C# Aspose.Cells 如何设置单元格样式的更多相关文章
- 用NPOI创建Excel、合并单元格、设置单元格样式、边框的方法
本篇文章小编为大家介绍,用NPOI创建Excel.合并单元格.设置单元格样式.边框的方法.需要的朋友参考下 今天在做项目中,遇到使用代码生成具有一定样式的Excel,找了很多资料,最后终于解决了,Ex ...
- NPOI 生成Excel (单元格合并、设置单元格样式:字段,颜色、设置单元格为下拉框并限制输入值、设置单元格只能输入数字等)
NPIO源码地址:https://github.com/tonyqus/npoi NPIO使用参考:源码中的 NPOITest项目 下面代码包括: 1.包含多个Sheet的Excel 2.单元格合并 ...
- python xlwt 设置单元格样式-合并单元格
xlwt模块详解--合并单元格 import xlwtworkbook = xlwt.Workbook()worksheet = workbook.add_sheet('My sheet')# 合并第 ...
- 创建excel,合并单元格,设置单元格样式
package com.huawei.excel; import java.io.File;import java.io.FileOutputStream;import java.util.Date; ...
- python xlwt 设置单元格样式
使用xlwt中的Alignment来设置单元格的对齐方式,其中horz代表水平对齐方式,vert代表垂直对齐方式. VERT_TOP = 0x00 上端对齐 VERT_CENTER = 0x01 居中 ...
- layui 动态表格设置单元格样式
col.push({ field: , templet: function (d) { ") { return '<span style="color:white;backg ...
- poi包的几行基本的设置单元格样式
——杂言:写过很多遍这段代码,今天姑且记录一下,便于翻阅. jar:poi-3.7.jar 注意:第8行应该调用cellStyle.setFillForeGroundColor(HSSFColor.G ...
- java操作Excel的poi 设置单元格的对其方式
设置单元格的对其方式 package com.java.poi; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.po ...
- java POI Excel 单元格样式
正如Html需要CSS一样,我们的POI生成的Excel同样需要样式才能更完美的表现我们的数据.下面还是从简单的例子出发,学习和了解POI的样式设计. 一.我的位置. 1 package com.my ...
随机推荐
- (转) qt: usb热插拔(linux);
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> ...
- EF的默认映射以及如何使用Data Annotations和Fluent API配置数据库的映射
I.EF的默认映射 上节我们创建项目,通过定义实体类就可以自动生成数据库,并且EF帮我们自动设置了数据库的主键.外键以及表名和字段的类型等,这就是EF的默认映射.具体分为: 数据库映射:Code Fi ...
- 关于APP测试的一点思考
1 系统入口部分要细化测试用例颗粒度 充分准备好测试数据 真实覆盖线上场景 比如注册验证码的获取 国内 国外手机 一般国外手机发送短信 打电话都要加上区号 2 新版本发布 有新功能上线 ...
- http和https协议的区别
内容摘自:转载注明Wosign 尊重知识产权 一 什么是HTTPS HTTPS全称为 安全超文本传输协议(Secure Hypertext Transfer Protocol)),是一个安全通信通道, ...
- gantt project 使用
市场上有不少项目计划类系统, 很多都是收费的, 还有很多都是web版, 这些都自然被排除了. 免费好用的还真不多, 今天简单介绍一下 gantt project 这个软件, 开源并且免费, 基于 ja ...
- [Reinforcement Learning] 马尔可夫决策过程
在介绍马尔可夫决策过程之前,我们先介绍下情节性任务和连续性任务以及马尔可夫性. 情节性任务 vs. 连续任务 情节性任务(Episodic Tasks),所有的任务可以被可以分解成一系列情节,可以看作 ...
- Python——合并指定文件夹下的所有excel文件
前提:该文件夹下所有文件有表头且具有相同的表头. import glob # 同下 from numpy import * #请提前在CMD下安装完毕,pip install numppy impor ...
- Python——Python+Pydev出现SyntaxError: Non-UTF-8 code
搭建好Python+Pydev后发现每次输入中文,包括注释,会出现语法错误提示,如: SyntaxError: Non-UTF-8 code starting with... 可通过下面方法解决. 1 ...
- JS中JSON和string字符串相互转换
在Firefox,chrome,opera,safari,ie9,ie8等高级浏览器直接可以用JSON对象的stringify()和parse()方法. JSON.stringify(obj)将JSO ...
- java aes CBC的填充方式发现
如下的java代码,手动对block进行填充后,使其为16的整数倍后,加密的时候竟然强行再填充了16位,我在尝试用golang实现这段加密时,反复修改了很久,发现golang版的总是比java加密出来 ...