Implement Errors and Boolean Value in Russian or Other Languages
Introduction
In the dynamic world of data analysis and visualization, the ability to seamlessly work with spreadsheet data is a valuable skill. Aspose.Cells for .NET is a powerful library that enables developers to create, manipulate, and convert spreadsheet files programmatically. In this tutorial, we will explore how to implement custom error values and boolean values in a specific language, such as Russian, using Aspose.Cells for .NET.
Prerequisites
Before we begin, make sure you have the following prerequisites:
- .NET Core or .NET Framework installed on your system.
- Visual Studio or any other .NET IDE of your choice.
- Familiarity with C# programming language.
- Basic understanding of working with spreadsheet data.
Import Packages
To get started, let’s import the necessary packages:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Step 1: Create a Custom Globalization Settings Class
In this step, we’ll create a custom GlobalizationSettings
class that will handle the translation of error values and boolean values to a specific language, in this case, Russian.
public class RussianGlobalization : GlobalizationSettings
{
public override string GetErrorValueString(string err)
{
switch (err.ToUpper())
{
case "#NAME?":
return "#RussianName-имя?";
}
return "RussianError-ошибка";
}
public override string GetBooleanValueString(bool bv)
{
return bv ? "RussianTrue-правда" : "RussianFalse-ложный";
}
}
In the RussianGlobalization
class, we override the GetErrorValueString
and GetBooleanValueString
methods to provide the desired translations for error values and boolean values, respectively.
Step 2: Load the Spreadsheet and Set the Globalization Settings
In this step, we’ll load the source spreadsheet and set the GlobalizationSettings
to the custom RussianGlobalization
class.
//Source directory
string sourceDir = "Your Document Directory";
//Output directory
string outputDir = "Your Document Directory";
//Load the source workbook
Workbook wb = new Workbook(sourceDir + "sampleRussianGlobalization.xlsx");
//Set GlobalizationSettings in Russian Language
wb.Settings.GlobalizationSettings = new RussianGlobalization();
Make sure to replace "Your Document Directory"
with the actual path to your source and output directories.
Step 3: Calculate the Formula and Save the Workbook
Now, we’ll calculate the formula and save the workbook in PDF format.
//Calculate the formula
wb.CalculateFormula();
//Save the workbook in pdf format
wb.Save(outputDir + "outputRussianGlobalization.pdf");
Step 4: Execute the Code
To execute the code, create a new console application or a class library project in your preferred .NET IDE. Add the code from the previous steps, and then run the ImplementErrorsAndBooleanValueInRussianOrAnyOtherLanguage.Run()
method.
public class ImplementErrorsAndBooleanValueInRussianOrAnyOtherLanguage
{
public static void Run()
{
//Source directory
string sourceDir = "Your Document Directory";
//Output directory
string outputDir = "Your Document Directory";
//Load the source workbook
Workbook wb = new Workbook(sourceDir + "sampleRussianGlobalization.xlsx");
//Set GlobalizationSettings in Russian Language
wb.Settings.GlobalizationSettings = new RussianGlobalization();
//Calculate the formula
wb.CalculateFormula();
//Save the workbook in pdf format
wb.Save(outputDir + "outputRussianGlobalization.pdf");
Console.WriteLine("ImplementErrorsAndBooleanValueInRussianOrAnyOtherLanguage executed successfully.\r\n");
}
}
After running the code, you should find the output PDF file in the specified output directory, with the error values and boolean values displayed in the Russian language.
Conclusion
In this tutorial, we learned how to implement custom error values and boolean values in a specific language, such as Russian, using Aspose.Cells for .NET. By creating a custom GlobalizationSettings
class and overriding the necessary methods, we were able to seamlessly integrate the desired translations into our spreadsheet processing workflow. This technique can be extended to support other languages as well, making Aspose.Cells for .NET a versatile tool for international data analysis and reporting.
FAQ’s
What is the purpose of the GlobalizationSettings
class in Aspose.Cells for .NET?
The GlobalizationSettings
class in Aspose.Cells for .NET allows you to customize the display of error values, boolean values, and other locale-specific information in your spreadsheet data. This is particularly useful when working with international audiences or when you need to present data in a specific language.
Can I use the RussianGlobalization
class with other Aspose.Cells for .NET features?
Yes, the RussianGlobalization
class can be used in conjunction with other Aspose.Cells for .NET features, such as reading, writing, and manipulating spreadsheet data. The custom globalization settings will be applied throughout your spreadsheet processing workflows.
How can I extend the RussianGlobalization
class to support more error values and boolean values?
To extend the RussianGlobalization
class to support more error values and boolean values, you can simply add more cases to the GetErrorValueString
and GetBooleanValueString
methods. For example, you can add cases for other common error values, such as "#DIV/0!"
or "#REF!"
, and provide the corresponding Russian translations.
Is it possible to use the RussianGlobalization
class with other Aspose products?
Yes, the GlobalizationSettings
class is a common feature across various Aspose products, including Aspose.Cells for .NET, Aspose.Words for .NET, and Aspose.PDF for .NET. You can create a similar custom globalization settings class and use it with other Aspose products to ensure a consistent language experience across your applications.
Where can I find more information and resources on Aspose.Cells for .NET?
You can find more information and resources on Aspose.Cells for .NET on the Aspose documentation website. Here, you can find detailed API references, user guides, examples, and other helpful resources to assist you in your development journey.