Implementieren Sie Fehler und Boolesche Werte auf Russisch oder in einer anderen Sprache mit JavaScript in C++
Contents
[
Hide
]
Mögliche Verwendungsszenarien
Wenn Sie Microsoft Excel auf Russisch oder mit einer anderen Sprache oder Region verwenden, werden Fehler und Boolesche Werte entsprechend angezeigt. Sie können ein ähnliches Verhalten mit Aspose.Cells for JavaScript in C++ erreichen, indem Sie die WorkbookSettings.globalizationSettings-Eigenschaft verwenden. Sie müssen die folgenden Methoden der GlobalizationSettings-Klasse überschreiben.
Fehler und boolesche Werte in Russisch oder einer anderen Sprache implementieren
Der folgende Beispielcode veranschaulicht, wie Fehler und boolesche Werte in Russisch oder einer anderen Sprache implementiert werden. Bitte überprüfen Sie die in diesem Code verwendete Beispiel Excel-Datei und deren Ausgabe-PDF. Der Screenshot zeigt den Unterschied zwischen der Beispiel-Excel-Datei und der Ausgabe-PDF zur Referenz.

Beispielcode
<!DOCTYPE html>
<html>
<head>
<title>Aspose.Cells Example</title>
<meta charset="utf-8" />
<style>
body { font-family: Arial, sans-serif; margin: 20px; }
#downloadLink { display: none; margin-top: 10px; display: inline-block; }
#result p { margin: 8px 0; }
</style>
</head>
<body>
<h1>Russian Globalization Example</h1>
<input type="file" id="fileInput" accept=".xls,.xlsx" />
<button id="runExample">Run Example</button>
<a id="downloadLink">Download Result</a>
<div id="result"></div>
</body>
<script src="aspose.cells.js.min.js"></script>
<script type="text/javascript">
const { Workbook, SaveFormat } = AsposeCells;
AsposeCells.onReady({
license: "/lic/aspose.cells.enc",
fontPath: "/fonts/",
fontList: [
"arial.ttf",
"NotoSansSC-Regular.ttf"
]
}).then(() => {
console.log("Aspose.Cells initialized");
});
// Russian Globalization
class RussianGlobalization extends AsposeCells.GlobalizationSettings {
errorValueString(err) {
switch (err.toUpperCase()) {
case "#NAME?":
return "#RussianName-имя?";
}
return "RussianError-ошибка";
}
booleanValueString(bv) {
return bv ? "RussianTrue-правда" : "RussianFalse-ложный";
}
}
document.getElementById('runExample').addEventListener('click', async () => {
const fileInput = document.getElementById('fileInput');
const resultDiv = document.getElementById('result');
resultDiv.innerHTML = '';
if (!fileInput.files.length) {
resultDiv.innerHTML = '<p style="color: red;">Please select an Excel file.</p>';
return;
}
const file = fileInput.files[0];
const arrayBuffer = await file.arrayBuffer();
// Load the source workbook
const workbook = new Workbook(new Uint8Array(arrayBuffer));
// Set GlobalizationSettings in Russian Language
workbook.settings.globalizationSettings = new RussianGlobalization();
// Calculate the formula
workbook.calculateFormula();
// Save the workbook in pdf format
const outputData = workbook.save(SaveFormat.Pdf);
const blob = new Blob([outputData], { type: 'application/pdf' });
const downloadLink = document.getElementById('downloadLink');
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = 'outputRussianGlobalization.pdf';
downloadLink.style.display = 'inline-block';
downloadLink.textContent = 'Download PDF File';
resultDiv.innerHTML = '<p style="color: green;">Operation completed successfully! Click the download link to get the PDF.</p>';
});
</script>
</html>