Fuente de tema de encabezados y cuerpo con C++

Fuente de tema para encabezados y cuerpo en Excel

En Excel, selecciona la pestaña Inicio, haz clic en la caja desplegable de fuente, verás “Fuentes de tema” con dos fuentes de tema: Calibri Light (Encabezados) y Calibri (Cuerpo) en la parte superior con la configuración regional en inglés.

Fuentes del tema

Si se selecciona Fuente de tema, el nombre de la fuente se mostrará de manera diferente en diferentes regiones. Si no deseas que la fuente cambie automáticamente en diferentes regiones, no selecciones las dos Fuentes de tema.

Cambiar fuentes de encabezados y cuerpo de forma programática

Con Aspose.Cells for C++, podemos verificar si la fuente predeterminada es una fuente de tema o establecer la fuente de tema con la propiedad Font.GetSchemeType().

El siguiente código de muestra muestra cómo manipular la fuente del tema de forma programática.

#include <iostream>
#include "Aspose.Cells.h"

using namespace Aspose::Cells;

int main()
{
    Aspose::Cells::Startup();

    // Create a workbook object
    Workbook workbook(u"Book1.xlsx");

    // Get the default style
    Style defaultStyle = workbook.GetDefaultStyle();

    // Get the font scheme type
    FontSchemeType schemeType = defaultStyle.GetFont().GetSchemeType();

    // Check if the font is a theme font
    if (schemeType == FontSchemeType::Major || schemeType == FontSchemeType::Minor)
    {
        std::cout << "It's theme font" << std::endl;
    }

    // Change theme font to normal font
    defaultStyle.GetFont().SetSchemeType(FontSchemeType::None);

    // Set the modified default style back to the workbook
    workbook.SetDefaultStyle(defaultStyle);

    Aspose::Cells::Cleanup();
    return 0;
}

Obtiene dinámicamente la fuente del tema local de forma programática

A veces, nuestros servidores y las máquinas de los usuarios no están en la misma región. ¿Cómo podemos obtener la misma fuente que los usuarios desean para el procesamiento de archivos?

Debemos configurar las configuraciones regionales del sistema antes de cargar el archivo con la propiedad LoadOptions.GetRegion().

El siguiente ejemplo de código muestra cómo obtener la fuente de tema local.

#include <iostream>
#include "Aspose.Cells.h"

using namespace Aspose::Cells;

int main()
{
    Aspose::Cells::Startup();

    // Instantiate a new LoadOptions
    LoadOptions options;

    // Set the customer's region to Japan
    options.SetRegion(CountryCode::Japan);

    // Instantiate a new Workbook with the specified options
    Workbook workbook(u"Book1.xlsx", options);

    // Get the default style of the workbook
    Style defaultStyle = workbook.GetDefaultStyle();

    // Get the customer's local font name
    U16String localFontName = defaultStyle.GetFont().GetName();

    std::cout << "Local Font Name: " << localFontName.ToUtf8() << std::endl;

    Aspose::Cells::Cleanup();
    return 0;
}