使用 NPOI C# 将单元格格式化为百分比 [英] Format cell as Percentage with NPOI C#

查看:40
本文介绍了使用 NPOI C# 将单元格格式化为百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 NPOI 将特定的 XLS 单元格格式化为百分比"格式.我可以使用

I am trying to format a specific XLS cell to the "Percentage" format using NPOI. I am able to convert it to text using

(dataRow.GetCell(17) ?? dataRow.CreateCell(17)).CellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("Text");

但是如果我尝试用百分比来做它就行不通了.这是我正在尝试的代码

But if I try do it with percentage it doesnt work. This is the code I am trying

(dataRow.GetCell(17) ?? dataRow.CreateCell(17)).CellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("Percentage");

它只会将该单元格设置为通用.我将如何将其设置为百分比?请记住,我希望单元格中的值如 0.05(不是 5%),但格式为百分比.

It will just set that cell as Generic. How would I go about setting it as percentage? Please keep in mind I want the value e.g 0.05 to be in the cell (not 5%), but with the format as Percentage.

推荐答案

我找到了答案.我不得不使用:

I found the answer. I had to use:

(dataRow.GetCell(17) ?? dataRow.CreateCell(17)).CellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("0.00%");

它使它成为没有符号的 2dp 百分比

It make it 2dp percentage without the symbol

这篇关于使用 NPOI C# 将单元格格式化为百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆