Esporta il foglio di lavoro CSS separatamente in HTML di output
Possibili Scenari di Utilizzo
Aspose.Cells per Python via .NET fornisce la funzionalità di esportare separatamente il CSS del worksheet quando si converte il file Excel in HTML. Usa la proprietà HtmlSaveOptions.export_worksheet_css_separately per questo scopo e impostala su true durante il salvataggio del file Excel in formato HTML.
Esportare il Foglio di Stile CSS Separatamente nell’HTML di Output
Il seguente codice di esempio crea un file Excel, aggiunge del testo nella cella B5 di colore Rosso e poi lo salva nel formato HTML utilizzando la proprietà HtmlSaveOptions.export_worksheet_css_separately. Si prega di vedere l’HTML di output nel HTML generato dal codice per riferimento. All’interno si troverà stylesheet.css come risultato del codice di esempio.
Codice di Esempio
from aspose.cells import HtmlSaveOptions, Workbook | |
from aspose.pydrawing import Color | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Create workbook object | |
wb = Workbook() | |
# Access first worksheet | |
ws = wb.worksheets[0] | |
# Access cell B5 and put value inside it | |
cell = ws.cells.get("B5") | |
cell.put_value("This is some text.") | |
# Set the style of the cell - font color is Red | |
st = cell.get_style() | |
st.font.color = Color.red | |
cell.set_style(st) | |
# Specify html save options - export worksheet css separately | |
opts = HtmlSaveOptions() | |
opts.export_worksheet_css_separately = True | |
# Save the workbook in html | |
wb.save("outputExportWorksheetCSSSeparately.html", opts) |
Esporta un singolo foglio di lavoro in HTML
Quando un workbook con più fogli viene convertito in HTML usando Aspose.Cells per Python via .NET, crea un file HTML insieme a una cartella contenente CSS e più file HTML. Quando questo file HTML viene aperto nel browser, sono visibili le schede. Lo stesso comportamento è richiesto anche per un workbook con un singolo foglio quando viene convertito in HTML. In passato non veniva creata una cartella separata per i workbook con singolo foglio e veniva creato solo il file HTML. Tali file HTML non mostrano le schede quando aperti nel browser. MS Excel crea una cartella e HTML corretto anche per un singolo foglio e quindi lo stesso comportamento viene implementato usando le API Aspose.Cells per Python via .NET. Il file di esempio può essere scaricato dal seguente link per essere usato nel codice di esempio sotto:
Codice di Esempio
from aspose.cells import HtmlSaveOptions, Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Load the sample Excel file containing single sheet only | |
wb = Workbook(sourceDir + "sampleSingleSheet.xlsx") | |
# Specify HTML save options | |
options = HtmlSaveOptions() | |
# Set optional settings if required | |
options.encoding = "utf-8" | |
options.export_images_as_base64 = True | |
options.export_grid_lines = True | |
options.export_similar_border_style = True | |
options.export_bogus_row_data = True | |
options.exclude_unused_styles = True | |
options.export_hidden_worksheet = True | |
# Save the workbook in Html format with specified Html Save Options | |
wb.save(outputDir + "outputSampleSingleSheet.htm", options) |