セルのリッチテキストの一部をアクセスして更新する
Contents
[
Hide
]
Aspose.Cells for Python via .NET を使用すると、セルのリッチテキストの部分にアクセスして更新することができます。このために、Cell.get_characters() と Cell.set_characters() のメソッドを使用できます。これらのメソッドは、フォント名、フォントカラー、太字などのフォントのさまざまなプロパティにアクセスして更新するために使用できる FontSetting オブジェクトの配列を返し、受け入れます。
セルのリッチテキストの部分にアクセスして更新
次のコードは、ソースエクセルファイル を使用して、Cell.get_characters() と Cell.set_characters() の使用方法を示しています。ソースエクセルファイルには、セル A1 にリッチテキストが含まれています。3 つの部分に分かれ、それぞれ異なるフォントを使用しています。次のコードスニペットは、これらの部分にアクセスして最初の部分を新しいフォント名で更新します。最後に、ワークブックを出力エクセルファイル として保存します。開くと、テキストの最初の部分のフォントが “Arial” に変更されていることがわかります。
C# コードでセルのリッチテキストの部分にアクセスして更新する
This file contains hidden or 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
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
inputPath = dataDir + "Sample.xlsx" | |
outputPath = dataDir + "Output.out.xlsx" | |
workbook = Workbook(inputPath) | |
worksheet = workbook.worksheets[0] | |
cell = worksheet.cells.get("A1") | |
print("Before updating the font settings....") | |
fnts = cell.get_characters() | |
for i in range(len(fnts)): | |
print(fnts[i].font.name) | |
# Modify the first FontSetting Font Name | |
fnts[0].font.name = "Arial" | |
# And update it using SetCharacters() method | |
cell.set_characters(fnts) | |
print() | |
print("After updating the font settings....") | |
fnts = cell.get_characters() | |
for i in range(len(fnts)): | |
print(fnts[i].font.name) | |
# Save workbook | |
workbook.save(outputPath) |
サンプルコードによって生成されたコンソール出力
以下は、ソースエクセルファイル を使用して上記サンプルコードのコンソール出力です。
Before updating the font settings....
Century
Courier New
Verdana
After updating the font settings....
Arial
Courier New
Verdana