用来格式化数字的正确样式属性是什么(使用C#)。我想做两件事:
1)将五位数字格式化为邮政编码。(我不太确定要使用哪种样式属性来获得自定义的excel邮政编码格式)
2)格式化一个数字(双),使它没有任何逗号,并且只有两个尾随小数点。我尝试过使用"###0.00“作为自定义样式,但它似乎不起作用。
任何帮助都将不胜感激。
邮政编码:
//zipcode code
Style zipcodeStyle = targetCells[1, 1].GetStyle();
zipcodeStyle.Custom = "0####";
targetCells[rowindex - 20, 16].PutValue("01234");//test zipcode
targetCells[rowindex - 20, 16].SetStyle(zipcodeStyle);结果Excel值: 1234
号码代码:
targetCells[rowindex - 20, 45].PutValue("1234.56");
Style style = targetWs.Cells[rowindex - 20, 45].GetStyle();
style.Custom = "###0.00";
targetCells[rowindex - 20, 45].SetStyle(style);
targetCells[rowindex - 20, 45].Copy(sourceCells[rowindex, 26]);
//test value: 140,366.75结果Excel值: 140,366.75
发布于 2014-01-15 19:25:36
弄明白了。您必须将字符串数据格式化为文本。来自源单元格的数据必须放在文本公式中。对于邮政编码,应该是:
=text(datavalue, "00000") 所有美国的邮政编码都是5位长,所以从上面的例子中的前导零将被保留。至于数字格式,它也将改为文本,以保留尾随零。关于数字格式,应该是:
=text(datavalue, ".00")但是,在使用此方法之前,需要清除上面的数据值。结果将放在一个单元格中,您也应该能够对其执行数学操作。
https://stackoverflow.com/questions/21119010
复制相似问题