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 ...
随机推荐
- OpenLayers学习笔记(十一)— 飞机速度矢量线预测
在机场使用的空管系统中,飞机的速度矢量线差不多是这样的: 模拟飞机飞行时的速度矢量线,这里就大概做个类似效果: 什么叫速度矢量线呢,个人理解就是根据飞机当前速度和航向预测它在未来一段时间内的飞机轨迹, ...
- Vue学习笔记七:Vue中的样式
目录 两种样式 class样式 内联样式 两种样式 Vue中使用样式方式有两种,一种是class样式,一种是内联样式也就是style class样式 class样式使用的方式有5种,HTML如下 &l ...
- DirectX11 With Windows SDK--24 Render-To-Texture(RTT)技术的应用
前言 尽管在上一章的动态天空盒中用到了Render-To-Texture技术,但那是针对纹理立方体的特化实现.考虑到该技术的应用层面非常广,在这里抽出独立的一章专门来讲有关它的通用实现以及各种应用. ...
- linux路由表
Linux 内核的路由表通过 route 命令查看 Linux 内核的路由表: [root@VM_139_74_centos ~]# routeKernel IP routing tableDesti ...
- 转---Google Python编程风格指南
为帮助读者能够将代码准确格式化,我们提供了针对 Vim的配置文件 .对于Emacs用户,保持默认设置即可. 背景 Python 是 Google主要的脚本语言.这本风格指南主要包含的是针对python ...
- 【知乎Live】狼叔:如何正确的学习Node.js
文章链接 https://i5ting.github.io/How-to-learn-node-correctly/#1 或在 https://github.com/i5ting/How-to-lea ...
- Linux基础 - 系统优化及常用命令
目录 Linux基础系统优化及常用命令 Linux基础系统优化 网卡配置文件详解 ifup,ifdown命令 ifconfig命令 ifup,ifdown命令 ip命令 用户管理与文件权限篇 创建普通 ...
- 解决:在微信中访问app下载链接提示“已停止访问该网页”
前言 现如今微信对第三方推广链接的审核是越来越严格了,域名在微信中分享转发经常会被拦截,一旦被拦截用户就只能复制链接手动打开浏览器粘贴才能访问,要不然就是换个域名再推,周而复始.无论是哪一种情况都会面 ...
- es集群数据库~运维相关
一 数据同步方案 1 ES-JDBC 不能实现删除同步操作.MYSQL如果删除,ES不会删除 2 logstash-input-jdbc 能实现insert update,但是仍然不能实现删除 ...
- Pytorch学习笔记(一)Numpy SciPy MatPlotlib Tutorial
英文原文链接:http://cs231n.github.io/python-numpy-tutorial/ Numpy Numpy是Python中科学计算的核心库.它提供了一个高性能的多维数组对象,以 ...