Elektronik tabloyu HTML e dönüştürürken varsayılan yazı tipini ayarlayın
Elektronik tabloyu HTML’e dönüştürürken varsayılan yazı tipini ayarlayın
Aşağıdaki örnek kod bir çalışma kitabı oluşturur, ilk çalışma sayfasının B4 hücresine bir metin ekler ve yazı tipini bilinmeyen/bulunmayan bir yazı tipine ayarlar. Daha sonra, çalışma kitabını farklı varsayılan yazı tipi adları olarak Courier New, Arial, Times New Roman vb. ayarlayarak HTML olarak kaydeder.
Ekran görüntüsü, HtmlSaveOptions.default_font_name özelliği aracılığıyla farklı varsayılan yazı tipi adları ayarlamanın etkisini göstermektedir.
Kod, Courier New ile, Arial ile ve Times New Roman ile çıktı HTML dosyasını oluşturur.
Ö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 | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create workbook object and access first worksheet. | |
wb = Workbook() | |
ws = wb.worksheets[0] | |
# Access cell B4 and add some text inside it. | |
cell = ws.cells.get("B4") | |
cell.put_value("This text has some unknown or invalid font which does not exist.") | |
# Set the font of cell B4 which is unknown. | |
st = cell.get_style() | |
st.font.name = "UnknownNotExist" | |
st.font.size = 20 | |
cell.set_style(st) | |
# Now save the workbook in html format and set the default font to Courier New. | |
opts = HtmlSaveOptions() | |
opts.default_font_name = "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.default_font_name = "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.default_font_name = "Times New Roman" | |
wb.save(dataDir + "times_new_roman_out.htm", opts) |