Utilizzo della classe ChartGlobalizationSettings per impostare diverse lingue per il componente grafico con C++
Possibili Scenari di Utilizzo
Le API di Aspose.Cells hanno esposto la classe ChartGlobalizationSettings per gestire gli scenari in cui l’utente desidera impostare un componente del grafico in una lingua diversa, etichette personalizzate per i subtotali in un foglio di calcolo.
Introduzione alla classe ChartGlobalizationSettings
La classe ChartGlobalizationSettings attualmente offre i seguenti 8 metodi che possono essere sovrascritti in una classe personalizzata per tradurre come il nome di AxisTitle, AxisUnit, ChartTitle e così via in lingue diverse.
- GetAxisTitleName: Ottiene il nome del Titolo per l’Asse.
- GetAxisUnitName: Ottiene il Nome dell’Unità di Asse.
- GetChartTitleName: Ottiene il nome del Titolo del Grafico.
- GetLegendDecreaseName: Ottiene il nome di Diminuzione per la Leggenda.
- GetLegendIncreaseName: Ottiene il nome di aumento per la Leggenda.
- GetLegendTotalName: Ottiene il nome di Totale per la Leggenda.
- GetOtherName: Ottiene il nome delle etichette “Altro” per il Grafico.
- GetSeriesName: Ottiene il nome di Serie nel Grafico.
Traduzione personalizzata
Qui, creeremo un grafico a barre basato sui seguenti dati. I nomi dei componenti del grafico verranno visualizzati in inglese nel grafico. Useremo un esempio in lingua turca per mostrare come visualizzare il Titolo del Grafico, i nomi di Aumento/Diminuzione della Leggenda, il nome Totale e il Titolo dell’Asse in turco.
Codice di Esempio
Il seguente codice di esempio carica il file Excel di esempio.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
using namespace Aspose::Cells::Charts;
class TurkeyChartGlobalizationSettings : public ChartGlobalizationSettings
{
public:
TurkeyChartGlobalizationSettings() : ChartGlobalizationSettings() {}
U16String GetChartTitleName() override
{
return u"Grafik Başlığı"; // Chart Title
}
U16String GetLegendIncreaseName() override
{
return u"Artış"; // Increase
}
U16String GetLegendDecreaseName() override
{
return u"Düşüş"; // Decrease
}
U16String GetLegendTotalName() override
{
return u"Toplam"; // Total
}
U16String GetAxisTitleName() override
{
return u"Eksen Başlığı"; // Axis Title
}
};
void ChartGlobalizationSettingsTest()
{
// Create an instance of existing Workbook
U16String pathName = u"input.xlsx";
Workbook workbook(pathName);
// Set custom chartGlobalizationSettings, here is TurkeyChartGlobalizationSettings
TurkeyChartGlobalizationSettings* globalizationSettings = new TurkeyChartGlobalizationSettings();
workbook.GetSettings().GetGlobalizationSettings()->SetChartSettings(globalizationSettings);
// Get the worksheet
Worksheet worksheet = workbook.GetWorksheets().Get(0);
// Load the chart from source worksheet
ChartCollection chartCollection = worksheet.GetCharts();
Chart chart = chartCollection.Get(0);
// Chart Calculate
chart.Calculate();
// Get the chart title
Title title = chart.GetTitle();
// Output the name of the Chart title
std::cout << "\nWorkbook chart title: " << title.GetText().ToUtf8() << std::endl;
// Get the legend labels
Vector<U16String> legendEntriesLabels = chart.GetLegend().GetLegendLabels();
// Output the name of the Legend
for (int i = 0; i < legendEntriesLabels.GetLength(); i++)
{
std::cout << "\nWorkbook chart legend: " << legendEntriesLabels[i].ToUtf8() << std::endl;
}
// Output the name of the Axis title
Title categoryAxisTitle = chart.GetCategoryAxis().GetTitle();
std::cout << "\nWorkbook category axis title: " << categoryAxisTitle.GetText().ToUtf8() << std::endl;
delete globalizationSettings;
}
int main()
{
Aspose::Cells::Startup();
ChartGlobalizationSettingsTest();
Aspose::Cells::Cleanup();
return 0;
}
Output generato dal codice di esempio
Questo è l’output console del codice di esempio precedente.
Workbook chart title: Grafik Başlığı
Workbook chart legend: Artış
Workbook chart legend: Düşüş
Workbook chart legend: Toplam
Workbook category axis tile: Eksen Başlığı