//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 如何设置单元格样式的更多相关文章

  1. 用NPOI创建Excel、合并单元格、设置单元格样式、边框的方法

    本篇文章小编为大家介绍,用NPOI创建Excel.合并单元格.设置单元格样式.边框的方法.需要的朋友参考下 今天在做项目中,遇到使用代码生成具有一定样式的Excel,找了很多资料,最后终于解决了,Ex ...

  2. NPOI 生成Excel (单元格合并、设置单元格样式:字段,颜色、设置单元格为下拉框并限制输入值、设置单元格只能输入数字等)

    NPIO源码地址:https://github.com/tonyqus/npoi NPIO使用参考:源码中的 NPOITest项目 下面代码包括: 1.包含多个Sheet的Excel 2.单元格合并 ...

  3. python xlwt 设置单元格样式-合并单元格

    xlwt模块详解--合并单元格 import xlwtworkbook = xlwt.Workbook()worksheet = workbook.add_sheet('My sheet')# 合并第 ...

  4. 创建excel,合并单元格,设置单元格样式

    package com.huawei.excel; import java.io.File;import java.io.FileOutputStream;import java.util.Date; ...

  5. python xlwt 设置单元格样式

    使用xlwt中的Alignment来设置单元格的对齐方式,其中horz代表水平对齐方式,vert代表垂直对齐方式. VERT_TOP = 0x00 上端对齐 VERT_CENTER = 0x01 居中 ...

  6. layui 动态表格设置单元格样式

    col.push({ field: , templet: function (d) { ") { return '<span style="color:white;backg ...

  7. poi包的几行基本的设置单元格样式

    ——杂言:写过很多遍这段代码,今天姑且记录一下,便于翻阅. jar:poi-3.7.jar 注意:第8行应该调用cellStyle.setFillForeGroundColor(HSSFColor.G ...

  8. java操作Excel的poi 设置单元格的对其方式

    设置单元格的对其方式 package com.java.poi; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.po ...

  9. java POI Excel 单元格样式

    正如Html需要CSS一样,我们的POI生成的Excel同样需要样式才能更完美的表现我们的数据.下面还是从简单的例子出发,学习和了解POI的样式设计. 一.我的位置. 1 package com.my ...

随机推荐

  1. k-均值聚类算法1

    一.k-means算法: 1.优缺点: 优点:容易实现. 缺点:可能收敛到局部最小值,在大规模数据集上收敛较慢. 2.伪代码描述:

  2. python实现查找文件

    import os.pathwhile True: rootdir=input('请输入遍历文件夹的绝对路径:(q退出)') if rootdir=='q': break if not(os.path ...

  3. MFC:定时器

    1. 定时器设置 API:CWnd::SetTimer()     函数原型:UINT SetTimer(UINT nIDEvent, UINT nElapse, void (CALLBACK EXP ...

  4. (模拟) codeVs1160 蛇形矩阵

    题目描述 Description 小明玩一个数字游戏,取个n行n列数字矩阵(其中n为不超过100的奇数),数字的填补方法为:在矩阵中心从1开始以逆时针方向绕行,逐圈扩大,直到n行n列填满数字,请输出该 ...

  5. markdown 【demo】

    第一次开始 用markdown 编辑器 public class{ public static void main (String[] agrs){ System.out.println(" ...

  6. JGUI源码:实现蒙版层显示(18)

    有的时候需要显示一个蒙版层,蒙版层显示的主要原理是在指定元素比如div上创建一个子元素div,设置absolute.宽高100%.设置z-index置于顶层,设置半透明效果,fadein,fadeou ...

  7. PMP知识点(三)——挣值计算汇总表

    在新标签页打开. 附参考图 资料地址:http://pan.baidu.com/s/1bMNroq

  8. 移动端返回上一页,刚需!document.referrer 详解

    返回上一页,在PC端我们可以使用:history.go(-1)或者history.back(),可以正常返回第一层.这样,我们不需要上一页的 url 具体是什么,只要使用 history 一般都没啥问 ...

  9. Python3:输出当前目录所有文件的第二种方式-walk()函数

    上一篇,我们讲了用递归的方式输入所有文件路径,其实os还提供了一个好用的方法-walk() 简单看一下: 中文大意就是: 返回的是一个三元tupple(dirpath, dirnames, filen ...

  10. cocos2dx模拟器修改窗口大小

    修改模拟器窗口大小SimulatorWin.cpp搜索 frameSize修改frameSize = Size(1920*0.9, 1080*0.9);