Ottieni un elenco di font utilizzati in un foglio di calcolo o in un workbook
Possibili Scenari di Utilizzo
È spesso necessario conoscere i font utilizzati nel tuo workbook per scopi di rendering. Quando converti il tuo workbook in PDF o immagine, allora Aspose.Cells richiede che tutti i font necessari siano installati sul tuo sistema o presenti nella tua directory dei font. Se Aspose.Cells non è in grado di trovare il font necessario, cerca di sostituirlo con qualche altro font adatto presente sul tuo sistema o nella tua directory dei font e può sostituire il tuo font effettivo. Questo non solo comporta il rendering indesiderato di PDF o immagini ma richiede anche tempo di elaborazione per trovare font adatti.
Per gestire tali casi, dovresti sapere quali caratteri sono usati dal tuo workbook, poi installarli sul sistema in caso di ambiente Windows o collocarli nella directory dei caratteri in caso di ambiente Windows o Linux.
Aspose.Cells for JavaScript via C++ fornisce il metodo Workbook.fonts che restituisce l’elenco di tutti i font usati nella tua cartella di lavoro o foglio di calcolo.
Ottieni un elenco di font utilizzati in un foglio di calcolo o di lavoro
Il codice di esempio seguente carica il file excel di origine e recupera l’elenco di font utilizzati al suo interno. Ha un foglio di lavoro fittizio al quale sono stati aggiunti alcuni font fittizi a scopo illustrativo. Quando il codice stampa tutti i font all’interno del workbook, stampa anche quei font fittizi. La schermata seguente mostra il file excel di esempio e come sono elencati i font fittizi.

Codice di Esempio
<!DOCTYPE html>
<html>
<head>
<title>Aspose.Cells Get Fonts Example</title>
<meta charset="utf-8" />
</head>
<body>
<h1>Get Fonts from Workbook</h1>
<input type="file" id="fileInput" accept=".xls,.xlsx,.csv" />
<button id="runExample">Get Fonts</button>
<a id="downloadLink" style="display: none;">Download Result</a>
<div id="result"></div>
</body>
<script src="aspose.cells.js.min.js"></script>
<script type="text/javascript">
const { Workbook, SaveFormat, Worksheet, Cell, Utils } = AsposeCells;
AsposeCells.onReady({
license: "/lic/aspose.cells.enc",
fontPath: "/fonts/",
fontList: [
"arial.ttf",
"NotoSansSC-Regular.ttf"
]
}).then(() => {
console.log("Aspose.Cells initialized");
});
document.getElementById('runExample').addEventListener('click', async () => {
const fileInput = document.getElementById('fileInput');
if (!fileInput.files.length) {
document.getElementById('result').innerHTML = '<p style="color: red;">Please select an Excel file.</p>';
return;
}
const file = fileInput.files[0];
const arrayBuffer = await file.arrayBuffer();
// Instantiate workbook from uploaded file
const workbook = new Workbook(new Uint8Array(arrayBuffer));
// Get all the fonts inside the workbook (converted from getFonts())
const fonts = workbook.fonts;
// Print all the fonts into the result div
if (!fonts || fonts.length === 0) {
document.getElementById('result').innerHTML = '<p>No fonts found in the workbook.</p>';
return;
}
let html = '<h2>Fonts in Workbook</h2><ul>';
for (let i = 0; i < fonts.length; i++) {
html += `<li>${fonts[i].toString()}</li>`;
}
html += '</ul>';
document.getElementById('result').innerHTML = html;
});
</script>
</html>
Output della console
Aspose.Cells.Font [ Calibri; 11; Regular; Color [Black] ]
Aspose.Cells.Font [ Arial; 10; Regular; Color [A=255, R=0, G=0, B=0] ]
Aspose.Cells.Font [ Calibri; 10; Bold; Color [Black] ]
Aspose.Cells.Font [ Calibri; 10; Regular; Color [A=255, R=128, G=128, B=128] ]
Aspose.Cells.Font [ Calibri; 10; Regular; Color [A=255, R=55, G=98, B=104] ]
Aspose.Cells.Font [ Calibri; 16; Bold; Color [A=255, R=255, G=255, B=255] ]
Aspose.Cells.Font [ Calibri; 36; Regular; Color [A=255, R=55, G=98, B=104] ]
Aspose.Cells.Font [ Calibri; 20; Bold; Color [A=255, R=55, G=98, B=104] ]
Aspose.Cells.Font [ Calibri; 16; Regular; Color [A=255, R=55, G=98, B=104] ]
Aspose.Cells.Font [ Calibri; 11; Regular; Color [A=255, R=55, G=98, B=104] ]
Aspose.Cells.Font [ Calibri; 11; Bold; Color [A=255, R=55, G=98, B=104] ]
Aspose.Cells.Font [ Calibri; 11; Bold; Color [A=255, R=255, G=255, B=255] ]
Aspose.Cells.Font [ Calibri; 11; Italic; Color [A=255, R=55, G=98, B=104] ]
Aspose.Cells.Font [ Calibri; 16; Regular; Color [A=255, R=55, G=98, B=104] ]
Aspose.Cells.Font [ Calibri; 16; Bold; Color [A=255, R=55, G=98, B=104] ]
Aspose.Cells.Font [ Calibri; 16; Regular; Color [Black] ]
Aspose.Cells.Font [ Calibri; 16; Regular; Color [A=255, R=41, G=74, B=78] ]
Aspose.Cells.Font [ Calibri; 16; Regular; Color [A=255, R=41, G=74, B=78] ]
Aspose.Cells.Font [ Calibri; 12; Regular; Color [A=255, R=41, G=74, B=78] ]
Aspose.Cells.Font [ Calibri; 11; Regular; Color [A=255, R=41, G=74, B=78] ]
Aspose.Cells.Font [ Calibri; 11; Bold; Color [A=255, R=255, G=255, B=255] ]
Aspose.Cells.Font [ Dummy-Arial-X; 11; Regular; Color [Black] ]
Aspose.Cells.Font [ Dummy-Arial-Y; 11; Regular; Color [Black] ]
Aspose.Cells.Font [ Dummy-Arial-Z; 11; Regular; Color [Black] ]
Aspose.Cells.Font [ Dummy-Times-I; 11; Regular; Color [Black] ]
Aspose.Cells.Font [ Dummy-Times-II; 11; Regular; Color [Black] ]
Aspose.Cells.Font [ Dummy-Times-III; 11; Regular; Color [Black] ]
Aspose.Cells.Font [ Calibri; 10.5; Regular; Color [A=255, R=55, G=98, B=104] ]
Aspose.Cells.Font [ Calibri; 20; Regular; Color [A=255, R=55, G=98, B=104] ]
Aspose.Cells.Font [ Calibri; 11; Regular; Color [A=255, R=55, G=98, B=104] ]