Excel中的“单元格编号存储为文本"单元格 [英] cell in Excel "Number stored as text"

查看:71
本文介绍了Excel中的“单元格编号存储为文本"单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#程序,该程序可以获取旧版报告的文本文件并映射到Excel工作表.但是对于交易单元,它输出为数字存储为文本",这不允许任何格式.我们希望显示1,000.00,但只能显示为1000.

I have a C# program that takes a text file of a legacy report and maps to an excel sheet. but for the transaction cells it is output as "Number stored as text" this does not allow any formatting. We want to show 1,000.00 but it only as 1000.

有没有一种方法可以获取这种格式?这些列是余额"和金额".定义如下:

Is there a way I can get this formatting? those columns are Balance and Amount. here it is defined:

ndcRange = currentSheet.Cells[transactionRowNo + pageOffset, 13];
ndcRange.NumberFormat = "@";
ndcRange.Value2 = tr.Amount;

ndcRange = currentSheet.Cells[transactionRowNo + pageOffset, 16];
ndcRange.NumberFormat = "@";
ndcRange.Value2 = tr.Balance;

以下是完成某些格式设置的代码:

Here is some code where some formatting is done:

string balance = transaction;

if (lastSpaceIndex != -1)
{

   balance = transaction.Substring(lastSpaceIndex, (transaction.Length)lastSpaceIndex);

}

transac.Balance = balance;
transaction = transaction.Replace(balance, "");


transaction = transaction.Trim();

if (!string.IsNullOrWhiteSpace(transaction))
{
    transac.Description = transaction;
}
patient.TransactionsList.Add(transac);

推荐答案

使用Microsoft Excel对象库中的Range.NumberFormat.选中此链接.

Use Range.NumberFormat from the Microsoft Excel Object Library. Check this link.

示例代码:

oRng = oSheet.get_Range("C2", "C1000"); //change this range to suit your scenario
oRng.Formula = "<any formula you may be using already or skip it>";
oRng.NumberFormat = "#,##0.00"; 

参考:

如何从Microsoft Visual C#.NET自动化Microsoft Excel

StackOverflow示例

这篇关于Excel中的“单元格编号存储为文本"单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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