出力 HTML でワークシート CSS を個別にエクスポートする
Contents
[
Hide
]
考えられる使用シナリオ
Aspose.Cells は、Excel ファイルを HTML に変換するときに、ワークシートの CSS を個別にエクスポートする機能を提供します。HtmlSaveOptions.ExportWorksheetCSSSeparatelyこの目的のためにプロパティを設定し、真実 ExcelファイルをHTML形式で保存しています。
出力 HTML でワークシート CSS を個別にエクスポートする
次のサンプル コードは、Excel ファイルを作成し、セルにテキストを追加します。B5の赤color を使用して HTML 形式で保存しますHtmlSaveOptions.ExportWorksheetCSSSeparately財産。をご覧ください出力 HTML参照用のコードによって生成されます。見つけるだろうstylesheet.cssサンプルコードの結果としてその中に。
サンプルコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
シングル シート ワークブックを HTML にエクスポートする
複数のシートを含むワークブックを Aspose.Cells を使用して HTML に変換すると、CSS と複数の HTML ファイルを含むフォルダーと共に HTML ファイルが作成されます。この HTML ファイルをブラウザで開くと、タブが表示されます。 HTML に変換される場合、単一のワークシートを含むワークブックには同じ動作が必要です。 以前は、単一シートのワークブック用に別のフォルダーが作成されず、HTML ファイルのみが作成されました。このような HTML ファイルは、ブラウザで開いたときにタブが表示されません。 MS Excel は、1 つのシートに対して適切なフォルダーと HTML も作成するため、Aspose.Cells API を使用して同じ動作が実装されます。サンプル ファイルは、次のリンクからダウンロードして、以下のサンプル コードで使用できます。
サンプルコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |