我怎样才能更改使用C#中的Excel单元格中的文本格式? [英] How can i change the text format of a Excel Cell using C#?

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

问题描述

我目前正在写一个应用程序(C#)生成一个excel文件报告的基础上,其他报告。

I am currently writing an application (C#) to generate reports in a excel file, based on other reports.

的问题是,一旦从一个特定片的数目,并复制到另一个时,目标细胞是不正确格式化,并且数量正确确实没有显示

The problem is that, once get an number from a certain sheet, and copy to another one, the destination cell is not formated correctly, and the number does no display correctly.

E.g : 
Number from source : 14.34 
Number on destination : 14.345661

我如何格式化目的地小区迫使数格式化为相同源小区

How do i format the destination cell to force the number formating to be the same as the source cell.

谢谢!

推荐答案

定格/范围在Excel的格式可以设置通过代码。

The format of a given cell/range in excel can be set via code.

public void SetCustomFormat(string format, int r, int c)
{
    ((Excel.Range)xlWks.Cells[r, c]).NumberFormat = format;
}

在特定的情况下,我相信你会需要使用的格式# .00或###

In your specific case, I believe you would need to use the format "#.00" or "#.##"

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

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