Elektronik tabloyu HTML e dönüştürürken varsayılan yazı tipini ayarlayın

HTML olarak elektronik tabloyu oluştururken 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.DefaultFontName özelliği aracılığıyla farklı varsayılan yazı tiplerinin etkisini göstermektedir.

todo:image_alt_text

Kod, Courier New ile üretilen çıktı HTML dosyası, Arial ile üretilen çıktı HTML dosyası ve Times New Roman ile üretilen çıktı HTML dosyası oluşturur.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Directory path where output HTML files are to be saved
String dataDir = Utils.getSharedDataDir(SetDefaultFontWhileRenderingSpreadsheetToHTML.class) + "Conversion/";
//Create workbook object.
Workbook wb = new Workbook();
//Access first WorkSheet.
Worksheet ws = wb.getWorksheets().get(0);
//Access cell B4 and add some text inside it.
Cell cell = ws.getCells().get("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.getFont().setName("UnknownNotExist");
st.getFont().setSize(20);
cell.setStyle(st);
//Now save the workbook in html format and set the default font to Courier New.
HtmlSaveOptions opts = new HtmlSaveOptions();
opts.setDefaultFontName("Courier New");
wb.save(dataDir + "out_courier_new.htm", opts);
//Now save the workbook in html format once again but set the default font to Arial.
opts.setDefaultFontName("Arial");
wb.save(dataDir + "out_arial.htm", opts);
//Now save the workbook in html format once again but set the default font to Times New Roman.
opts.setDefaultFontName("Times New Roman");
wb.save(dataDir + "out_times_new_roman.htm", opts);