セルのHTML文字列を管理する

可能な使用シナリオ

特定のセルにスタイル付きデータを設定する必要がある場合、セルにHTML文字列を割り当てることができます。もちろん、セルのHTML文字列を取得することもできます。Aspose.Cellsはこの機能を提供しています。Aspose.Cellsはあなたの目標を達成するための以下のプロパティとメソッドを提供します。

Python Excelライブラリを使用してAspose.CellsのHTML文字列を取得および設定

この例では、次のことができます:

  1. ワークブックを作成し、いくつかのデータを追加します。
  2. 最初のワークシートで特定のセルを取得します。
  3. セルにHTML文字列を設定します。
  4. セルのHTML文字列を取得します。
from aspose.cells import Workbook
# Instantiating an Workbook object
workbook = Workbook()
# Obtaining the reference of the newly added worksheet
ws = workbook.worksheets[0]
cells = ws.cells
# Setting the value to the cells
cell = cells.get("A1")
cell.put_value("Fruit")
cell = cells.get("B1")
cell.put_value("Count")
cell = cells.get("C1")
cell.put_value("Price")
cell = cells.get("A2")
cell.put_value("Apple")
cell = cells.get("A3")
cell.put_value("Mango")
cell = cells.get("A4")
cell.put_value("Blackberry")
cell = cells.get("A5")
cell.put_value("Cherry")
c3 = cells.get("C3")
# set html string for C3 cell.
c3.html_string = "<b>test bold</b>"
c4 = cells.get("C4")
# set html string for C4 cell.
c4.html_string = "<i>test italic</i>"
# get the html string of specific cell.
print(c3.html_string)
print(c4.html_string)

サンプルコードによって生成された出力

上記のサンプルコードの出力を以下のスクリーンショットで示します。

todo:image_alt_text