使用EPPlus时将格式化后的值作为货币类型插入 [英] Insert formatted values as currency type while using EPPlus

查看:298
本文介绍了使用EPPlus时将格式化后的值作为货币类型插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用格式:

类型="$ ###,###,## 0.00"

type ="$###,###,##0.00"

获取货币并将格式类型分配给工作表单元格

for currency and assigning the format type to the worksheet cells

例如 wrkSheet.Cells[0].Style.Numberformat.Format = formatType;

但这在excel中作为文本类型插入. 我希望将其作为货币或数字插入,以便继续对插入的值(排序,总和等)进行分析.

But this is inserted as text type in excel. I want this to be inserted as Currency or Number in order to continue to do analysis on the values inserted (sort, sum etc).

当前,因为文本类型验证不正确. 有什么方法可以强制插入格式值的类型?

Currently as it is text type validations do not hold correct. Is there any way to force the type in which the formatted values can be inserted?

推荐答案

您的格式正确.您需要将值隐藏为其原始类型

Your formatting is correct. You needs to covert values to its native types

using (var package = new ExcelPackage())
{
    var worksheet = package.Workbook.Worksheets.Add("Sales list - ");
    worksheet.Cells[1, 1].Style.Numberformat.Format = "$###,###,##0.00";
    worksheet.Cells[1, 1].Value =Convert.ToDecimal(24558.4780);

    package.SaveAs(new FileInfo(path));
}

这篇关于使用EPPlus时将格式化后的值作为货币类型插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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