Aspose格式

什么是正确的样式属性用于在aspose中格式化数字(使用C#)。 我想做2件事情:

1)将一个五位数的数字格式化为一个邮政编码(我不太确定用哪个Style属性来获得自定义的Excel邮政编码格式)

2)格式化一个数字(double),使它没有任何逗号,只有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

弄清楚了。 您必须将string数据格式化为文本。 源单元格中的数据必须放在文本公式中。 对于邮政编码应该是:

 =text(datavalue, "00000") 

所有的美国邮政编码都是5位数字,所以上面例子中的前导零将被保留。 至于数字格式,它也将被改为文本以保留尾随零。 对于数字格式,应该是:

 =text(datavalue, ".00") 

然而,在使用这种方法之前,上面的数据值需要用逗号清除。 结果将被放置在一个单元格中,您也应该能够对其执行math运算。