禁用有关OfficeOpenXml中包含数值的Excel文本单元格的警告 [英] Disable warning about Excel text cell containing numeric value in OfficeOpenXml

查看:78
本文介绍了禁用有关OfficeOpenXml中包含数值的Excel文本单元格的警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 OfficeOpenXml 创建MS/Excel电子表格文件.一些列包含任意文本值.但是,当这些列中的单元格填充有数值(即,仅包含数字的文本值)时,Excel会在拐角处显示带有绿色小三角形的单元格,并显示警告此单元格中的数字为设置为文本格式或以撇号开头..

I'm using OfficeOpenXml to create an MS/Excel spreadsheet file. Some of the columns contain arbitrary text values. However, when cells in those columns are filled with numeric values (i.e., text values containing only digits), Excel displays those cells with a small green triangle in the corner, along with the warning that "The number in this cell is formatted as text or preceded by an apostrophe".

从技术上讲这是正确的,但是我不希望Excel显示警告.

Which is technically correct, but I do not want Excel to display the warning.

那么,如何将这些列或这些列中的单元格设置为严格的文本值,以便不将其标记为数字文本值?如何禁用警告,并强制Excel将这些单元格值接受为文本(仅)?

So how do I format those columns, or the cells in those columns, to be strictly text values, so that they will not be flagged as numeric text values? How do I disable the warning, and force Excel to accept those cell values as text (only)?

注意:我见过其他OpenXML软件包的解决方案,但没有专门针对OfficeOpenXml的解决方案.我也看到了将文本单元格值解释为数字的解决方案,但这与我想做的完全相反.

推荐答案

我们的另一种解决方法是 LoadFromText ,它填充单元格文本并似乎抑制了该单元格的数字文本"警告.因此,我使用这样的代码来填充有此问题的单元格:

Another solution is to us LoadFromText, which fills the cell text and seems to suppress the 'numeric text' warnings for the cell. So I use code like this for filling the cells that have this problem:

DataRow dr = ...;    // Query result row
...
cell[r, c].LoadFromText(Convert.ToString(dr["item"]));

这篇关于禁用有关OfficeOpenXml中包含数值的Excel文本单元格的警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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