将单元格的数据类型更改为双精度 [英] Changing DataType of cell to Double

查看:228
本文介绍了将单元格的数据类型更改为双精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用OpenXML创建Microsoft Excel文件.我正在尝试使用

I'm using OpenXML to create Microsoft Excel file. I'm trying to insert a double type variable (Example : 4.987456789) into the Excel using

Cell cell = new Cell()
{
    CellReference = "A2",
    DataType = CellValues.String,
    CellValue = new CellValue(Convert.ToString(value))
};

但是,在制作单元格时,它是文本形式,Excel会说此单元格中的数字格式为文本或以撇号开头".如何格式化单元格以插入双精度数?

But, when the cell is being made, it's in text form and Excel says "The number in this cell is formatted as text or preceded by an apostrophe." How can format the cell to insert double?

抱歉,是两倍吗?类型,然后按照此教程

Edit : Sorry, It's double? type and I follow this tutorial

推荐答案

使用CellValues.Number对我来说效果很好,例如:

Using CellValues.Number works fine for me, for example :

double? value = 4.9874567891;
Cell cell2 = new Cell()
{
    CellReference = "A2",
    DataType = CellValues.Number,
    CellValue = new CellValue(Convert.ToString(value))
};

在没有您得到警告的情况下,将双值打印为excel.

Double value printed to excel without the warning you got.

这篇关于将单元格的数据类型更改为双精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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