.net c# changing excel cell format

2019-08-16 07:30发布

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#?

标签: c# .net excel cell
2条回答
Rolldiameter
2楼-- · 2019-08-16 08:00

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.

查看更多
狗以群分
3楼-- · 2019-08-16 08:03

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

查看更多
登录 后发表回答