简体   繁体   English

如何更改Excel单元格值

[英]How can i change excel cell value

im exporting data from gridview to excel. 我将数据从gridview导出到excel。 This is my exported column: 这是我的导出列:

POSTING KEY
1
50
50

but the column seems in the gridview like that: 但是该列在gridview中看起来像这样:

POSTING KEY
01
50
50

Excel convert my string values to numeric when after export. 导出后,Excel将我的字符串值转换为数字。 But i must see "01". 但是我必须看到“ 01”。 How can i change excel cell type or cell value in code when before save file.? 保存文件之前,如何更改代码中的Excel单元格类型或单元格值?

From Excel, highlight the column or the cell, right click and select "Format Cells", under the "Number" tab, click "Custom" under the Category:. 在Excel中,突出显示列或单元格,右键单击并选择“设置单元格格式”,在“数字”选项卡下,单击“类别:”下的“自定义”。 In the Type: textbox, key in "00". 在“类型:”文本框中,键入“ 00”。

You can export text with a apostrophe suffix. 您可以导出带有撇号后缀的文本。 for eg to display 01 instead of 1, you need to set cell's value as '01 and not just 01 Excel will take this value as text instead of number. 例如,要显示01而不是1,则需要将单元格的值设置为'01,而不仅仅是01 Excel会将此值作为文本而不是数字。 But in this case you will see a Error SamrtTag in Excel saying "Number stored as Text" which can be turned off from preferences. 但是在这种情况下,您将在Excel中看到一个错误的SamrtTag,上面写着“数字存储为文本”,可以从首选项中将其关闭。

When you read or write a cell there are two values you can look at. 读取或写入单元格时,您可以查看两个值。 The first one is value (eg cell.Value ) which is the one you are probably setting. 第一个是值(例如cell.Value ),它可能是您要设置的值。 The second is NumberFormat (eg cell.NumberFormat ). 第二个是NumberFormat(例如cell.NumberFormat )。 This is a string a will represent the format of the value when displayed in Excel, set this to an appropriate value (use the string representations in Excel if you're not sure which one you want). 这是一个字符串,它将代表在Excel中显示时值的格式,将其设置为适当的值(如果不确定要使用哪个字符串,请在Excel中使用字符串表示形式)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM