セルのHTML文字列を管理する
Contents
[
Hide
]
可能な使用シナリオ
特定のセルにスタイル付きデータを設定する必要がある場合、セルにHTML文字列を割り当てることができます。もちろん、セルのHTML文字列を取得することもできます。Aspose.Cellsはこの機能を提供しています。Aspose.Cellsはあなたの目標を達成するための以下のプロパティとメソッドを提供します。
Aspose.Cellsを使用してHTML文字列を取得および設定する
この例では、次のことができます:
- ワークブックを作成し、いくつかのデータを追加します。
- 最初のワークシートで特定のセルを取得します。
- セルにHTML文字列を設定します。
- セルの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
//Instantiating an Workbook object | |
Workbook workbook = new Workbook(); | |
//Obtaining the reference of the newly added worksheet | |
Worksheet ws = workbook.Worksheets[0]; | |
Cells cells = ws.Cells; | |
//Setting the value to the cells | |
Cell cell = cells["A1"]; | |
cell.PutValue("Fruit"); | |
cell = cells["B1"]; | |
cell.PutValue("Count"); | |
cell = cells["C1"]; | |
cell.PutValue("Price"); | |
cell = cells["A2"]; | |
cell.PutValue("Apple"); | |
cell = cells["A3"]; | |
cell.PutValue("Mango"); | |
cell = cells["A4"]; | |
cell.PutValue("Blackberry"); | |
cell = cells["A5"]; | |
cell.PutValue("Cherry"); | |
Cell c3 = cells["C3"]; | |
//set html string for C3 cell. | |
c3.HtmlString = "<b>test bold</b>"; | |
Cell c4 = cells["C4"]; | |
//set html string for C4 cell. | |
c4.HtmlString = "<i>test italic</i>"; | |
//get the html string of specific cell. | |
Console.WriteLine(c3.HtmlString); | |
Console.WriteLine(c4.HtmlString); |
サンプルコードによって生成された出力
上記のサンプルコードの出力を以下のスクリーンショットで示します。