共用方式為


NamedRange.NumberFormat 屬性

取得或設定 NamedRange 控制項的格式化程式碼。

命名空間:  Microsoft.Office.Tools.Excel
組件:  Microsoft.Office.Tools.Excel (在 Microsoft.Office.Tools.Excel.dll 中)

語法

'宣告
Property NumberFormat As Object
Object NumberFormat { get; set; }

屬性值

型別:System.Object
NamedRange 控制項的格式化程式碼。

備註

如果 NamedRange 控制項中所有的儲存格都沒有相同的數字格式,則這個屬性會傳回 nullnull 參考 (即 Visual Basic 中的 Nothing)。

格式化程式碼是與 [設定儲存格格式] 對話方塊中的 [格式化程式碼] 選項相同的字串。 Format 功能使用的格式化程式碼字串與 NumberFormat 和 NumberFormatLocal 屬性所使用的不同。

範例

下列程式碼範例會使用 NumberFormat 屬性,格式化 NamedRange 中的日期字串。 這個範例也會使用 NumberFormatLocal 屬性,以使用者的語言顯示日期格式。

這是示範文件層級自訂的範例。

Private formatRange As Microsoft.Office.Tools.Excel.NamedRange

Private Sub ApplyNumberFormatting()
    formatRange = Me.Controls.AddNamedRange( _
        Me.Range("C1"), "formatRange")

    Me.formatRange.Value2 = "4-Apr-1974"
    Me.formatRange.NumberFormat = "m/d/yyyy"

    ' Display the number format in the language of the user.
    MessageBox.Show("The number format for the NamedRange is: " & _
        Me.formatRange.NumberFormatLocal.ToString())
End Sub
Microsoft.Office.Tools.Excel.NamedRange formatRange;
private void ApplyNumberFormatting()
{
    formatRange = this.Controls.AddNamedRange(
         this.Range["C1"], "formatRange");

    this.formatRange.Value2 = "4-Apr-1974";
    this.formatRange.NumberFormat = "m/d/yyyy";

    // Display the number format in the language of the user.
    MessageBox.Show("The number format for the NamedRange is: " +
        this.formatRange.NumberFormatLocal.ToString());
}

.NET Framework 安全性

請參閱

參考

NamedRange 介面

Microsoft.Office.Tools.Excel 命名空間