簡體   English   中英

設定格式

[英]Aspose Formatting

在aspose中使用數字格式化格式的正確樣式屬性是什么(使用C#)。 我想做兩件事:

1)將五位數的數字設置為郵政編碼。(我不太確定要使用哪種Style屬性來獲取自定義的excel郵政編碼格式)

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

弄清楚了。 您必須將字符串數據格式化為文本。 來自源單元格的數據必須放在文本公式內。 郵政編碼應該為:

=text(datavalue, "00000")  

所有美國郵政編碼均為5位數字,因此將保留上述示例中的前導零。 至於數字格式,它也將更改為文本,以保留尾隨零。 對於數字格式,應為:

=text(datavalue, ".00")

但是,在使用此方法之前,必須清除逗號以上的數據值。 結果將被放置在一個單元格中,您也應該能夠對其執行數學運算。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM