简体   繁体   English

使用C#导出到Excel

[英]Export to Excel using C#

I'm exporting the values in the grid to excel through C# code. 我正在通过C#代码将网格中的值导出为ex​​cel。 When i open the exported excel, the string column is displayed as integer and the leading '0' in that field gets deleted. 当我打开导出的Excel时,字符串列显示为整数,并且该字段中的前导“ 0”被删除。 how to handle this. 如何处理。

This isn't a programming issue; 这不是编程问题; it's Excel's default way of displaying what it thinks are numbers. 这是Excel显示其认为是数字的默认方式。

It assumes that 00001 is a number and should be displayed as 1 . 假定00001是一个数字,应显示为1 Change your cells to display "Text" instead of numbers in Excel. 更改单元格以显示“文本”,而不是Excel中的数字。

A quick way to get around this is to prefix your cell value with an apostrophe. 解决此问题的一种快速方法是在单元格值前加上撇号。

Excel hides the apostrophe automatically and forces the text mode for the cell to Text Excel自动隐藏撇号并强制将单元格的文本模式设置为“ Text

Try it directly in Excel and you'll see what I mean eg type '07799123477 into a cell with General text formatting (the default) 直接在Excel中尝试,您将明白我的意思,例如,将'07799123477具有General文本格式的单元格(默认设置)

I have no experience in making Excel files but when entering text in Excel you can write '00123. 我没有制作Excel文件的经验,但是在Excel中输入文本时,您可以输入'00123。 The ' makes the whole difference. '起到了很大的作用。

使用mso-number-format:\\@样式设置TD mso-number-format:\\@

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

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