Imposta il carattere predefinito durante il rendering del foglio di calcolo su HTML
Contents
[
Hide
]
Aspose.Cells consente di impostare il carattere predefinito durante il rendering del foglio di calcolo su HTML. Utilizzare ilHtmlSaveOptions.DefaultFontName per questo scopo. Questa proprietà è utile quando in un foglio di calcolo sono presenti alcune celle con caratteri non validi o inesistenti. Quindi quelle celle verranno visualizzate in un carattere specificato con ilHtmlSaveOptions.DefaultFontName proprietà.
Imposta il carattere predefinito durante il rendering del foglio di calcolo su HTML
Il seguente codice di esempio crea una cartella di lavoro e aggiunge del testo nella cella B4 del primo foglio di lavoro e ne imposta il carattere su un carattere sconosciuto/inesistente. Quindi salva la cartella di lavoro in HTML impostando diversi nomi di caratteri predefiniti come Courier New, Arial, Times New Roman, ecc.
Lo screenshot mostra l’effetto dell’impostazione di diversi nomi di font predefiniti tramiteHtmlSaveOptions.DefaultFontNameproprietà.
Il codice genera il fileuscita file HTML con Corriere Nuovo , iluscita HTML con Arial , e iloutput HTML file con Times New Roman.
Codice d’esempio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object and access first worksheet. | |
Workbook wb = new Workbook(); | |
Worksheet ws = wb.Worksheets[0]; | |
// Access cell B4 and add some text inside it. | |
Cell cell = ws.Cells["B4"]; | |
cell.PutValue("This text has some unknown or invalid font which does not exist."); | |
// Set the font of cell B4 which is unknown. | |
Style st = cell.GetStyle(); | |
st.Font.Name = "UnknownNotExist"; | |
st.Font.Size = 20; | |
cell.SetStyle(st); | |
// Now save the workbook in html format and set the default font to Courier New. | |
HtmlSaveOptions opts = new HtmlSaveOptions(); | |
opts.DefaultFontName = "Courier New"; | |
wb.Save(dataDir + "out_courier_new_out.htm", opts); | |
// Now save the workbook in html format once again but set the default font to Arial. | |
opts.DefaultFontName = "Arial"; | |
wb.Save(dataDir + "out_arial_out.htm", opts); | |
// Now save the workbook in html format once again but set the default font to Times New Roman. | |
opts.DefaultFontName = "Times New Roman"; | |
wb.Save(dataDir + "times_new_roman_out.htm", opts); |