Condividi tramite


Proprietà Chart.Name

Ottiene il nome del controllo Chart.

Spazio dei nomi:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)

Sintassi

'Dichiarazione
ReadOnly Property Name As String
    Get
string Name { get; }

Valore proprietà

Tipo: System.String
Nome del controllo Chart.

Note

Quando si crea un controllo Chart, Excel imposta la proprietà Name sulla stringa "Grafico sheetname n", dove n rappresenta il numero dei grafici incorporati sul foglio di lavoro. Ad esempio, se si aggiunge un Chart a Foglio1 ed è il primo grafico incorporato nel foglio di lavoro, la proprietà Name disporrà del valore Foglio1 Grafico 1.

Anche se la proprietà Name è di sola lettura, è possibile modificare una porzione del nome utilizzando la proprietà Name della proprietà padre Microsoft.Office.Interop.Excel.ChartObject. Il nuovo nome specificato sostituisce la sottostringa "Grafico n" nella stringa restituita dalla proprietà Name. Ad esempio, il codice seguente modifica il valore della proprietà Name di un controllo Chart da Foglio1 Grafico 1 a Foglio1 SalesChart.

Private Sub RenameChart()
    ' Set some test data and create a new Chart.
    Globals.Sheet1.Range("A1", "A5").Value2 = 22
    Globals.Sheet1.Range("B1", "B5").Value2 = 55

    Dim Chart1 As Microsoft.Office.Tools.Excel.Chart = _
        Globals.Sheet1.Controls.AddChart(Globals.Sheet1.Range("D2", "H12"), _
        "renameChartExample")
    Chart1.SetSourceData(Me.Range("A1", "B5"), Excel.XlRowCol.xlColumns)
    Chart1.ChartType = Excel.XlChartType.xl3DColumn

    ' Displays "Sheet1 Chart 1".
    MessageBox.Show("The default chart name is: " & Chart1.Name)

    ' Set the name of the parent ChartObject of this embedded Chart.
    Dim ChartObjectParent As Excel.ChartObject = TryCast(Chart1.Parent, Excel.ChartObject)
    ChartObjectParent.Name = "SalesChart"

    ' Displays "Sheet1 SalesChart".
    MessageBox.Show("The default chart name is: " & Chart1.Name)
End Sub
private void RenameChart()
{
    // Set some test data and create a new Chart.
    Globals.Sheet1.Range["A1", "A5"].Value2 = 22;
    Globals.Sheet1.Range["B1", "B5"].Value2 = 55;

    Microsoft.Office.Tools.Excel.Chart chart1 = Globals.Sheet1.Controls.AddChart(
        Globals.Sheet1.Range["D2", "H12"], "renameChartExample");
    chart1.SetSourceData(Globals.Sheet1.Range["A1", "B5"], Excel.XlRowCol.xlColumns);
    chart1.ChartType = Excel.XlChartType.xl3DColumn;

    // This message box displays "Sheet1 Chart 1".
    MessageBox.Show("The default chart name is: " + chart1.Name);

    // Set the name of the parent ChartObject of this embedded Chart.
    Excel.ChartObject chartObjectParent = chart1.Parent as Excel.ChartObject;
    chartObjectParent.Name = "SalesChart";

    // This message box displays "Sheet1 SalesChart".
    MessageBox.Show("The new chart name is: " + chart1.Name);
}

Sicurezza di .NET Framework

Vedere anche

Riferimenti

Chart Interfaccia

Spazio dei nomi Microsoft.Office.Tools.Excel