-
NPOI2.2.0.0实例详解(八)—设置EXCEL单元格【数字格式】
- 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 Program7
- {
- static void Main(string[] args)
- {
-
-
-
- IWorkbook myworkbook = new XSSFWorkbook();
-
-
- ISheet mysheet = myworkbook.CreateSheet("sheet1");
- mysheet.SetColumnWidth(0, 20 * 256);
- mysheet.SetColumnWidth(1, 20 * 256);
-
-
- IRow row0 = mysheet.CreateRow(0); row0.CreateCell(0).SetCellValue(2013.143); row0.CreateCell(1).SetCellValue("转化为汉字大写");
- IRow row1 = mysheet.CreateRow(1); row1.CreateCell(0).SetCellValue(123152013.143); row1.CreateCell(1).SetCellValue("改变小数精度");
- IRow row2 = mysheet.CreateRow(2); row2.CreateCell(0).SetCellValue(123152013.143); row2.CreateCell(1).SetCellValue("分段添加,号");
- IRow row3 = mysheet.CreateRow(3); row3.CreateCell(0).SetCellValue(123152013.143); row3.CreateCell(1).SetCellValue("科学计数法");
- IRow row4 = mysheet.CreateRow(4); row4.CreateCell(0).SetCellValue(-123152013.143); row4.CreateCell(1).SetCellValue("正数与负数的区分(负数红色)");
- IRow row5 = mysheet.CreateRow(5); row5.CreateCell(0).SetCellValue(123152013.77); row5.CreateCell(1).SetCellValue("整数部分+分数");
- IRow row6 = mysheet.CreateRow(6); row6.CreateCell(0).SetCellValue(123152013.77); row6.CreateCell(1).SetCellValue("分数");
- IRow row7 = mysheet.CreateRow(7); row7.CreateCell(0).SetCellValue(0.333); row7.CreateCell(1).SetCellValue("百分数");
-
-
- IDataFormat dataformat = myworkbook.CreateDataFormat();
-
- ICellStyle style0 = myworkbook.CreateCellStyle();
- style0.DataFormat = dataformat.GetFormat("[DbNum2][$-804]General");
-
- ICellStyle style1 = myworkbook.CreateCellStyle();
- style1.DataFormat = dataformat.GetFormat("0.0");
-
- ICellStyle style2 = myworkbook.CreateCellStyle();
- style2.DataFormat = dataformat.GetFormat("#,##0.0");
-
- ICellStyle style3 = myworkbook.CreateCellStyle();
- style3.DataFormat = dataformat.GetFormat("0.00E+00");
-
- ICellStyle style4 = myworkbook.CreateCellStyle();
- style4.DataFormat = dataformat.GetFormat("0.00;[Red]-0.00");
-
- ICellStyle style5 = myworkbook.CreateCellStyle();
- style5.DataFormat = dataformat.GetFormat("# ??/??");
-
- ICellStyle style6 = myworkbook.CreateCellStyle();
- style6.DataFormat = dataformat.GetFormat("??/??");
-
- ICellStyle style7 = myworkbook.CreateCellStyle();
- style7.DataFormat = dataformat.GetFormat("0.00%");
-
-
- row0.GetCell(0).CellStyle = style0;
- row1.GetCell(0).CellStyle = style1;
- row2.GetCell(0).CellStyle = style2;
- row3.GetCell(0).CellStyle = style3;
- row4.GetCell(0).CellStyle = style4;
- row5.GetCell(0).CellStyle = style5;
- row6.GetCell(0).CellStyle = style6;
- row7.GetCell(0).CellStyle = style7;
-
-
- FileStream file = new FileStream(@"E:myworkbook7.xlsx", FileMode.Create);
- myworkbook.Write(file);
- file.Close();
- }
- }
- }
-
相关阅读:
Oracle:SQL语句--撤销用户权限
Oracle:SQL语句--给用户赋权限
RSTP端口状态迁移过程详解
LSB算法分析与实现
工厂方法模式
Ceasar
区域性名称和标识符
Packet Tracer网络模拟实验实记
H3C-OSPF
H3C-RIP
-
原文地址:https://www.cnblogs.com/lenther2002/p/5799339.html
Copyright © 2020-2023
润新知