Çalışma Sayfası CSS'sini Çıktı HTML'de Ayrı Olarak Dışa Aktar
Olası Kullanım Senaryoları
Aspose.Cells, Excel dosyanızı HTML’e dönüştürdüğünüzde çalışma sayfası CSS’sini ayrı olarak dışa aktarma özelliği sağlar. Lütfen bu amaçla HtmlSaveOptions.ExportWorksheetCSSSeparately özelliğini kullanın ve Excel dosyasını HTML biçiminde kaydederken bunu doğru olarak ayarlayın.
Çalışma Sayfası CSS’sini Çıktı HTML’de Ayrı Olarak Dışa Aktar
Aşağıdaki örnek kod bir Excel dosyası oluşturur, B5 hücresine Kırmızı renkte bir miktar metin ekler ve ardından HtmlSaveOptions.ExportWorksheetCSSSeparately özelliğini kullanarak HTML biçiminde kaydeder. Lütfen bkzçıkış HTMLreferans için kod tarafından oluşturulur. İçinde örnek kodun bir sonucu olarak stylesheet.css dosyasını bulacaksınız.
Basit kod
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
//Create workbook object | |
Workbook wb = new Workbook(); | |
//Access first worksheet | |
Worksheet ws = wb.getWorksheets().get(0); | |
//Access cell B5 and put value inside it | |
Cell cell = ws.getCells().get("B5"); | |
cell.putValue("This is some text."); | |
//Set the style of the cell - font color is Red | |
Style st = cell.getStyle(); | |
st.getFont().setColor(Color.getRed()); | |
cell.setStyle(st); | |
//Specify html save options - export worksheet css separately | |
HtmlSaveOptions opts = new HtmlSaveOptions(); | |
opts.setExportWorksheetCSSSeparately(true); | |
//Save the workbook in html | |
wb.save("outputExportWorksheetCSSSeparately.html", opts); |
Tek sayfalık çalışma kitabını HTML’e aktar
Birden çok sayfası olan bir çalışma kitabı Aspose.Cells kullanılarak HTML’e dönüştürüldüğünde, CSS ve birden çok HTML dosyası içeren bir klasörle birlikte bir HTML dosyası oluşturur. Bu HTML dosyası tarayıcıda açıldığında sekmeler görünür. Tek çalışma sayfalı bir çalışma kitabı HTML’e dönüştürüldüğünde aynı davranış gerekir. Daha önce tek sayfalık çalışma kitapları için ayrı bir klasör oluşturulmuyordu ve yalnızca HTML dosyası oluşturuluyordu. Böyle bir HTML dosyası, tarayıcıda açıldığında sekme göstermez. Excel, tek sayfalar için de uygun klasör ve HTML oluşturur ve dolayısıyla aynı davranış Aspose.Cells kullanılarak uygulanır. Aşağıdaki örnek kodda kullanmak için örnek dosya aşağıdaki bağlantıdan indirilebilir:
Basit kod
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// Load the sample Excel file containing single sheet only | |
Workbook wb = new Workbook(srcDir + "sampleSingleSheet.xlsx"); | |
// Specify HTML save options | |
HtmlSaveOptions options = new HtmlSaveOptions(); | |
// Set optional settings if required | |
options.setEncoding(Encoding.getUTF8()); | |
options.setExportImagesAsBase64(true); | |
options.setExportGridLines(true); | |
options.setExportSimilarBorderStyle(true); | |
options.setExportBogusRowData(true); | |
options.setExcludeUnusedStyles(true); | |
options.setExportHiddenWorksheet(true); | |
//Save the workbook in Html format with specified Html Save Options | |
wb.save(outDir + "outputSampleSingleSheet.htm", options); |