C#中的Excel互操作:如何格式单元存储值作为文本 [英] C# Excel Interop: How to format cells to store values as text

查看:247
本文介绍了C#中的Excel互操作:如何格式单元存储值作为文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的数字从 DataTable的Excel电子表格和所有这些数字都是5位数与前一个0,如果数字本身是不超过5位数(所以395将被存储为00395,例如)。

I'm writing numbers to an Excel spreadsheet from a DataTable and all of these numbers are 5 digits long with preceding 0s if the number itself is less than 5 digits long (so 395 would be stored as 00395, for example).

当输入这些数字到Excel(使用C#),它的存储它们为数字并消除前述0。有没有什么办法可以从格式化C#中的细胞,为了得到的值存储为文本而不是数字?

When entering these numbers into Excel (using C#), it's storing them as numbers and eliminating the preceding 0s. Is there any way I can format the cells from C# in order to get the values to be stored as text rather than numbers?

推荐答案

可以 SomeRange.NumberFormat =@; 或你前面加上 值,并将其写入单元格,Excel将其视为一个数字存储-AS-文本,并提供可视的提示。

You can SomeRange.NumberFormat = "@"; or if you prefix the value with a ' and write it to the cell excel will treat it as a number-stored-as-text and provide a visual cue.

这篇关于C#中的Excel互操作:如何格式单元存储值作为文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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