スプレッドシートのレンダリング中にデフォルトのフォントを HTML に設定
Contents
[
Hide
]
Aspose.Cells を使用すると、スプレッドシートを HTML にレンダリングする際にデフォルトのフォントを設定できます。HtmlSaveOptions.DefaultFontNameこの目的のために。このプロパティは、無効なフォントまたは存在しないフォントを含むセルがスプレッドシートにある場合に役立ちます。次に、これらのセルは、で指定されたフォントでレンダリングされますHtmlSaveOptions.DefaultFontName財産。
スプレッドシートのレンダリング中にデフォルトのフォントを HTML に設定
次のサンプル コードでは、ワークブックを作成し、最初のワークシートのセル B4 にテキストを追加し、そのフォントを不明または存在しないフォントに設定します。次に、Courier New、Arial、Times New Roman などのさまざまな既定のフォント名を設定して、ワークブックを HTML に保存します。
スクリーンショットは、さまざまなデフォルトのフォント名を設定した効果を示していますHtmlSaveOptions.DefaultFontName財産。
コードは、Courier New で HTML ファイルを出力 、HTML を Arial で出力、 そしてそのTimes New RomanでHTMLファイルを出力.
サンプルコード
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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object and access first worksheet. | |
Workbook wb = new Workbook(); | |
Worksheet ws = wb.Worksheets[0]; | |
// Access cell B4 and add some text inside it. | |
Cell cell = ws.Cells["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.Font.Name = "UnknownNotExist"; | |
st.Font.Size = 20; | |
cell.SetStyle(st); | |
// Now save the workbook in html format and set the default font to Courier New. | |
HtmlSaveOptions opts = new HtmlSaveOptions(); | |
opts.DefaultFontName = "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.DefaultFontName = "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.DefaultFontName = "Times New Roman"; | |
wb.Save(dataDir + "times_new_roman_out.htm", opts); |