Çıktı HTML sindeki Sayfa CSS sini Ayrı Ayrı Dışa Aktarma
Olası Kullanım Senaryoları
Aspose.Cells for Python via .NET, Excel dosyanızı HTML’ye dönüştürürken çalışma sayfası CSS’sini ayrı olarak dışa aktarma özelliği sunar. Bu amaçla HtmlSaveOptions.export_worksheet_css_separately özelliğini kullanın ve kaydederken true olarak ayarlayın.
Çıktı HTML’sindeki Sayfa CSS’sini Ayrı Ayrı Dışa Aktarma
Aşağıdaki örnek kod, bir Excel dosyası oluşturur, B5 hücresine kırmızı renkte bir metin ekler ve ardından HtmlSaveOptions.export_worksheet_css_separately özelliğini kullanarak HTML formatında kaydeder. Referans için kod tarafından oluşturulan çıktı HTML’si‘nı inceleyin. Örnek kodun bir çıktısı olarak içinde stylesheet.css bulacaksınız.
Örnek Kod
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) |
Tek Çalışsayı İş Kitabını HTML’ye Dışa Aktarma
Çok sayfalı çalışma kitabı Aspose.Cells for Python via .NET kullanılarak HTML’ye dönüştürüldüğünde, HTML dosyası ve beraberinde CSS içeren klasör ve çok sayfalı HTML dosyaları oluşturulur. Bu HTML dosyası tarayıcıda açıldığında sekmeler görünür. Aynı davranış, tek sayfalık çalışma kitapları için de geçerlidir. Daha önce, yalnızca HTML dosyası oluşturulur ve sekmeler gösterilmezdi. Bu tarz HTML dosyası tarayıcıda açıldığında sekmeleri göstermez. Microsoft Excel, tek sayfalık çalışma kitabı için de uygun klasör yapısı ve HTML oluşturur ve bu nedenle, Aspose.Cells for Python via .NET API’leri kullanılarak aynı davranış sağlanmıştır. Aşağıdaki bağlantıdan örnek dosyayı indirebilir ve aşağıdaki örnek kodda kullanabilirsiniz:
Örnek Kod
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) |