Çıktı HTML sindeki Sayfa CSS sini Ayrı Ayrı Dışa Aktarma

Olası Kullanım Senaryoları

Aspose.Cells, Excel dosyanızı HTML’ye dönüştürdüğünüzde çalışsayı CSS’sini ayrı ayrı dışa aktarmayı sağlar. Bu amaçla HtmlSaveOptions.ExportWorksheetCSSSeparately özelliğini kullanın ve Excel dosyasını HTML formatında 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.ExportWorksheetCSSSeparately ö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

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Create workbook object
Workbook wb = new Workbook();
//Access first worksheet
Worksheet ws = wb.Worksheets[0];
//Access cell B5 and put value inside it
Cell cell = ws.Cells["B5"];
cell.PutValue("This is some text.");
//Set the style of the cell - font color is Red
Style st = cell.GetStyle();
st.Font.Color = Color.Red;
cell.SetStyle(st);
//Specify html save options - export worksheet css separately
HtmlSaveOptions opts = new HtmlSaveOptions();
opts.ExportWorksheetCSSSeparately = true;
//Save the workbook in html
wb.Save("outputExportWorksheetCSSSeparately.html", opts);

Tek Çalışsayı İş Kitabını HTML’ye Dışa Aktarma

Aspose.Cells tarafından birden fazla sayfaya sahip bir çalışsayının HTML’ye dönüştürülmesi durumunda, HTML dosyası ve CSS ile birlikte birden çok HTML dosyası içeren bir klasör oluşturur. Bu HTML dosyası tarayıcıda açıldığında sekmeler görünür. Bu sekmeler, tek çalışsayılı bir iş kitabı HTML’ye dönüştürüldüğünde gereklidir. Daha önce tek sayfalı çalışma kitapları için ayrı klasör oluşturulmamış ve sadece HTML dosyası oluşturulmuştu. Bu tür HTML dosyaları, tarayıcıda açıldığında sekme göstermez. MS Excel ayrıca tek sayfalı için uygun klasör ve HTML oluşturur ve bu nedenle Aspose.Cells API’leri kullanılarak aynı davranış uygulanır. Örnek dosyayı aşağıdaki bağlantıdan indirebilirsiniz:

sampleSingleSheet.xlsx

Örnek Kod

// 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
Workbook wb = new Workbook(sourceDir + "sampleSingleSheet.xlsx");
// Specify HTML save options
Aspose.Cells.HtmlSaveOptions options = new Aspose.Cells.HtmlSaveOptions();
// Set optional settings if required
options.Encoding = System.Text.Encoding.UTF8;
options.ExportImagesAsBase64 = true;
options.ExportGridLines = true;
options.ExportSimilarBorderStyle = true;
options.ExportBogusRowData = true;
options.ExcludeUnusedStyles = true;
options.ExportHiddenWorksheet = true;
//Save the workbook in Html format with specified Html Save Options
wb.Save(outputDir + "outputSampleSingleSheet.htm", options);