Cell のリッチ テキストの一部にアクセスして更新する
Contents
[
Hide
]
Aspose.Cells では、セルのリッチ テキストの一部にアクセスして更新できます。この目的のために、Cell.getCharacters() および Cell.setCharacters() メソッドを使用できます。これらのメソッドは、フォント名、フォントの色、太さなどのフォントのさまざまなプロパティにアクセスして更新するために使用できる FontSetting オブジェクトの配列を返し、受け入れます。
Cell のリッチ テキストの一部にアクセスして更新する
次のコードは、ソースエクセルファイル提供されたリンクからダウンロードできます。ソースの Excel ファイルには、セル A1 にリッチ テキストがあります。 3 つの部分があり、各部分は異なるフォントです。これらの部分にアクセスし、最初の部分を新しいフォント名で更新します。最後に、ワークブックを次のように保存します出力エクセルファイル.開くと、テキストの最初の部分のフォントが に変更されていることがわかります。「アリエル」.
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AccessAndUpdatePortions.class); | |
Workbook workbook = new Workbook(dataDir + "source.xlsx"); | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cell cell = worksheet.getCells().get("A1"); | |
System.out.println("Before updating the font settings...."); | |
FontSetting[] fnts = cell.getCharacters(); | |
for (int i = 0; i < fnts.length; i++) { | |
System.out.println(fnts[i].getFont().getName()); | |
} | |
// Modify the first FontSetting Font Name | |
fnts[0].getFont().setName("Arial"); | |
// And update it using SetCharacters() method | |
cell.setCharacters(fnts); | |
System.out.println(); | |
System.out.println("After updating the font settings...."); | |
fnts = cell.getCharacters(); | |
for (int i = 0; i < fnts.length; i++) { | |
System.out.println(fnts[i].getFont().getName()); | |
} | |
// Save workbook | |
workbook.save(dataDir + "output.xlsx"); |
コンソール出力
以下は、上記のサンプル コードを使用したコンソール出力です。ソースエクセルファイル.
Before updating the font settings....
Century
Courier New
Verdana
After updating the font settings....
Arial
Courier New
Verdana