.net c# changing excel cell format

て烟熏妆下的殇ゞ 提交于 2019-12-11 16:03:05

问题


I'm writing a record to Excel such as 1/6 but Excel shows this as a date. How can I change the Excel cell type by c#?


回答1:


What do you want to see? Try writing '1/6 if you want a string, or =1/6 is you want the number.




回答2:


If you have data that can be interpreted multiple ways (1/2, fraction or Jan 2, etc), you need to put an apostrophe (') before the data. That, or set the cell's format to Text.

When programming with Excel, the best thing to do is start recording a macro and perform the steps you would normally take to format the cells. Stop recording and go into Excel's VBA editor and see what happens. Often, the recorder puts a lot of extra commands in, but you can learn a thing or two by looking at the code.



来源:https://stackoverflow.com/questions/1346927/net-c-sharp-changing-excel-cell-format

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!