Excel documents, being a widely-used electronic spreadsheet across the globe, often involve multi-language collaboration in various scenarios. Against this backdrop, we introduce AI-powered translation technology, which not only accurately identifies and translates text content but also preserves the original data formats and structures, significantly enhancing work efficiency and accuracy while reducing communication costs incurred by language differences. In this article, we will introduce how to translate Excel using Spire.XLS AI.
Install Spire.XLS for .NET
The Excel AI integrated into Spire.XLS for .NET package, hence to begin with, you need to add the DLL files included in the Spire.XLS for .NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.XLS
Request a License Key of AI Product
A license key is required to run Spire.XLS AI, please contact our sales department (sales@e-iceblue.com) to request one.
Use AI to Translate Excel
Spire.XLS AI provides the ExcelAI class, which supports intelligent translation of either all content within a worksheet or specific ranges within specific worksheets. Below is an overview of the key methods involved in implementing this functionality:
- UploadWorkbook(Workbook wb): This method is used to upload a Workbook object processed by Spire.XLS to the AI server, facilitating the integration of Excel content with the AI system's data.
- ExcelTranslate(List<CellRange> srcRanges, string language): This method is designed to translate the content within specified cell ranges from worksheets into the specified target language.
- ExcelTranslate(List<Worksheet> srcWorksheets, string language, bool translateSheetName = true): This method is responsible for translating all content across a list of source worksheets, optionally including worksheet names, into the specified target language.
Translate Contents from Worksheets in C#
The following steps introduce how to translate the content within worksheets:
- Create a Workbook class instance.
- Load an Excel document using Workbook.LoadFromFile() method.
- Create an ExcelAI class instance.
- Upload the workbook to AI system using ExcelAI.UploadWorkbook() method.
- Create a list and store all worksheets from workbook.
- Translate content within worksheets into specified language using ExcelTranslate(List<Worksheet> srcWorksheets, string language, bool translateSheetName = true) method.
- Save the translated workbook using Workbook.SaveToFile () method.
- C#
using Spire.Xls; using Spire.Xls.AI; using System.Collections.Generic; // Define the file path of the Excel document string inputfile = "Input.xlsx"; // Create a new instance of the Workbook Workbook wb = new Workbook(); // Load the Excel file wb.LoadFromFile(inputfile); // Create a new instance of the ExcelAI ExcelAI excelAI = new ExcelAI(); // Upload the workbook to AI system excelAI.UploadWorkbook(wb); // Create a list to store worksheets List worksheets = new List(); // Iterate through each worksheet foreach (Worksheet worksheet in wb.Worksheets) { // Add the worksheet to the list worksheets.Add(worksheet); } // Translate the content of worksheets into Spanish excelAI.ExcelTranslate(worksheets, "spanish"); // Save the translated workbook to a new Excel file wb.SaveToFile("output.xlsx", ExcelVersion.Version2016);
Translate Contents from Ranges in C#
The following steps introduce how to translate the content within specified ranges:
- Create a Workbook class instance.
- Load an Excel document using Workbook.LoadFromFile() method.
- Create an ExcelAI class instance.
- Upload the workbook to AI system using ExcelAI.UploadWorkbook() method.
- Create a list to store cell ranges.
- Get the specified worksheet and add some cell ranges into the list.
- Translate content within the ranges into specified language using ExcelTranslate(List<CellRange> srcRanges, string language) method.
- Save the translated workbook using Workbook.SaveToFile () method.
- C#
using Spire.Xls; using Spire.Xls.AI; using System.Collections.Generic; // Define the file path of the Excel document string inputfile = "Input.xlsx"; // Create a new instance of the Workbook Workbook wb = new Workbook(); // Load the Excel file wb.LoadFromFile(inputfile); // Create a new instance of the ExcelAI ExcelAI excelAI = new ExcelAI(); // Upload the workbook to AI system excelAI.UploadWorkbook(wb); // Get the first worksheet Worksheet worksheet = wb.Worksheets[0]; // Create a list to store cell ranges List ranges = new List(); // Add two ranges to the list ranges.Add(worksheet.Range["B1"]); ranges.Add(worksheet.Range["H2"]); // Translate the content of ranges into Chinese excelAI.ExcelTranslate(ranges, "chinese"); // Save the translated workbook to a new Excel file wb.SaveToFile("output.xlsx", ExcelVersion.Version2016);