NPOI2.2.0.0实例详解(十)—设置EXCEL单元格【文本格式】
2015-12-10 09:55
537 查看
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using NPOI.HSSF.UserModel; using NPOI.SS.Formula.Eval; using NPOI.SS.Formula.Functions; using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; using NPOI.POIFS.FileSystem; using NPOI.HPSF; using System.IO; using NPOI.SS.Util; using System.Drawing; using NPOI.HSSF.Util; namespace NPOI { class Program9 { static void Main(string[] args) { //说明:设置文本格式 //1.创建EXCEL中的Workbook IWorkbook myworkbook = new XSSFWorkbook(); //2.创建Workbook中的Sheet ISheet mysheet = myworkbook.CreateSheet("sheet1"); mysheet.SetColumnWidth(0, 40 * 256); //3.创建Row中的Cell并赋值 IRow row0 = mysheet.CreateRow(0); row0.CreateCell(0).SetCellValue("130925199662080044"); IRow row1 = mysheet.CreateRow(1); row1.CreateCell(0).SetCellValue(""+DateTime.Now+""); //4.创建CellStyle与DataFormat并加载格式样式 IDataFormat dataformat = myworkbook.CreateDataFormat(); //【Tips】 // 1.使用@ 或 text 都可以 // 2.再也不用为身份证号发愁了 ICellStyle style0 = myworkbook.CreateCellStyle(); style0.DataFormat = dataformat.GetFormat("@"); ICellStyle style1 = myworkbook.CreateCellStyle(); style1.DataFormat = dataformat.GetFormat("text"); //5.将CellStyle应用于具体单元格 row0.GetCell(0).CellStyle = style0; row1.GetCell(0).CellStyle = style1; //6.保存 FileStream file = new FileStream(@"E:\myworkbook9.xlsx", FileMode.Create); myworkbook.Write(file); file.Close(); } } }
运行后,效果如下图所示【演示了文本格式的设置】
相关文章推荐
- 不借助 Wine 和云服务:新项目能让 Linux 完整运行微软 Office 套件
- 使用Python生成Excel格式的图片
- WPS Office:Linux 上的 Microsoft Office 的免费替代品
- Excel 曝出 Power Query 安全漏洞,1.2 亿用户易受远程 DDE 攻击
- [软件咨询]WPS2012正式版已发布 金山Office移动版4.0发布
- VBA将excel数据表生成JSON文件
- excel vba 限制工作表的滚动区域代码
- excel vba 高亮显示当前行代码
- 用Coldfusion生成 OFFICE 文件的代码
- 重现 Office 2007 中的菜单和工具栏的方法
- C#.NET获取拨号连接的宽带连接方法
- C#.Net ArrayList的使用方法
- Office Word九条常用技巧
- Microsoft Office 2007 SP1 简体中文正式版 升级包官方下载地址
- 官方 WPS office 2005 个人精装版 下载
- SQL 导入导出Excel数据的语句
- 文本、Excel、Access数据导入SQL Server2000的方法
- PowerShell中使用.NET将程序集加入全局程序集缓存
- C#导出数据到Excel文件的方法
- .net(c#)中的new关键字详细介绍