.net C#更改Excel单元格格式 [英] .net c# changing excel cell format

查看:168
本文介绍了.net C#更改Excel单元格格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将诸如1/6之类的记录写入Excel,但是Excel将其显示为日期。如何通过c#更改Excel单元格类型?

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/2 ,分数或1月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.

使用Excel进行编程时,最好的做法是开始记录宏并执行通常要格式化的步骤细胞。停止录制并进入Excel的VBA编辑器,看看会发生什么。记录器通常会输入很多额外的命令,但是您可以通过看一下代码来学习一两个东西。

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.

这篇关于.net C#更改Excel单元格格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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