Implement Error and Boolean Value in Russian or Other Languages

Introduction

In the ever-evolving field of data analysis and visualization, the ability to work seamlessly with spreadsheet data is paramount. Aspose.Cells for .NET is a robust library that enables developers to create, manipulate, and convert spreadsheet files programmatically. This tutorial will guide you in implementing custom error and boolean values in Russian using Aspose.Cells for .NET.

Prerequisites

Before we get started, ensure you have the following prerequisites:

  1. .NET Core or .NET Framework installed on your system.
  2. Visual Studio or another .NET IDE of your choice.
  3. Basic familiarity with the C# programming language.
  4. A general understanding of spreadsheet data handling.

Import Required Packages

To kick things off, let’s import the necessary packages:

using System;
using Aspose.Cells;

Step 1: Create a Custom Globalization Settings Class

In this step, we will define a custom GlobalizationSettings class to manage the translation of error and boolean values to Russian.

public class RussianGlobalization : GlobalizationSettings
{
    public override string GetErrorValueString(string err)
    {
        switch (err.ToUpper())
        {
            case "#NAME?":
                return "#RussianName-имя?";
            case "#DIV/0!":
                return "#RussianDivZero-ДелениеНаНоль";
            case "#REF!":
                return "#RussianRef-СсылкаНедопустима";
            // Add more cases as needed
        }
        return "RussianError-ошибка";
    }

    public override string GetBooleanValueString(bool bv)
    {
        return bv ? "RussianTrue-правда" : "RussianFalse-ложный";
    }
}

In the RussianGlobalization class, we’ve overridden the GetErrorValueString and GetBooleanValueString methods to provide the desired Russian translations for specific error and boolean values.

Step 2: Load the Spreadsheet and Set Globalization Settings

Next, we will load the source spreadsheet and apply our RussianGlobalization class settings.

// Set directories for source and output
string sourceDir = "Your Document Directory";
string outputDir = "Your Document Directory";

// Load the workbook
Workbook wb = new Workbook(sourceDir + "sampleRussianGlobalization.xlsx");

// Apply Russian globalization settings
wb.Settings.GlobalizationSettings = new RussianGlobalization();

Remember to replace "Your Document Directory" with the actual paths to your directories.

Step 3: Calculate Formulas and Save the Workbook

Now, let’s calculate the formulas in the workbook and save the output as a PDF.

// Calculate formulas
wb.CalculateFormula();

// Save the workbook as a PDF
wb.Save(outputDir + "outputRussianGlobalization.pdf");

Step 4: Execute the Code

To execute the code, create a new console application or class library project in your chosen .NET IDE. Include the code from previous steps and run the method:

public class ImplementErrorsAndBooleanValueInRussian 
{
    public static void Run()
    {
        string sourceDir = "Your Document Directory";
        string outputDir = "Your Document Directory";
        
        Workbook wb = new Workbook(sourceDir + "sampleRussianGlobalization.xlsx");
        wb.Settings.GlobalizationSettings = new RussianGlobalization();
        wb.CalculateFormula();
        wb.Save(outputDir + "outputRussianGlobalization.pdf");
        
        Console.WriteLine("Localization of error and boolean values executed successfully.");
    }
}

After running this code, you will find the output PDF in the specified output directory, with error and boolean values displayed in Russian.

Conclusion

In this tutorial, we explored how to implement custom error and boolean values in a specific language, Russian, using Aspose.Cells for .NET. By creating a custom GlobalizationSettings class and overriding the necessary methods, we smoothly integrated the required translations into our spreadsheet processing workflow. This approach can be easily extended to support additional languages, making Aspose.Cells for .NET a versatile choice for international data analysis and reporting.

FAQ’s

What is the GlobalizationSettings class used for in Aspose.Cells for .NET?

GlobalizationSettings allows you to customize how error values, boolean values, and other locale-specific information are displayed in your spreadsheets. This feature is particularly beneficial for catering to international audiences or presenting data in specific languages.

Can I use RussianGlobalization with other Aspose.Cells features?

Absolutely! The RussianGlobalization class can be seamlessly integrated with other Aspose.Cells functionalities, allowing for consistent localization throughout your spreadsheet processing tasks.

How can I add more error values and boolean values to RussianGlobalization?

To extend the RussianGlobalization class, you can add additional cases in the GetErrorValueString and GetBooleanValueString methods for other common error values like "#NUM!", "#VALUE!", etc., and provide their Russian translations.

Can I apply the RussianGlobalization class to other Aspose products?

Yes! The GlobalizationSettings class is a feature available in various Aspose products, including Aspose.Words and Aspose.PDF. You can create similar custom classes for other products to maintain a consistent multilingual experience across your applications.

Where can I find more resources on Aspose.Cells for .NET?

You can explore additional resources and documentation on Aspose.Cells for .NET, where you’ll find detailed API references, user guides, examples, and other helpful materials to enhance your development experience.