首页 文章

Aspose格式

提问于
浏览
2

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

1)将五位数字格式化为邮政编码 . (我不太确定使用哪种Style属性来获取自定义excel zipcode格式)

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

1 回答

  • 1

    弄清楚了 . 你必须将字符串数据格式化为文本 . 源单元格中的数据必须放在文本公式中 . 对于邮政编码,它应该是:

    =text(datavalue, "00000")
    

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

    =text(datavalue, ".00")
    

    但是,在使用此方法之前,需要使用逗号清除上面的数据值 . 结果将放在单元格中,您也应该能够对其执行数学运算 .

相关问题