グラフのデータ ラベルの形状をテキストに合わせてサイズ変更する
Contents
[
Hide
]
Excel アプリケーションが提供するテキストに合わせて図形のサイズを変更するテキストが内部に収まるように形状のサイズを大きくするには、Chart の DataLabels のオプション。このオプションは、グラフのデータ ラベルのいずれかを選択することにより、Excel インターフェイスでアクセスできます。右クリックして選択DataLabels の書式設定メニュー。の上サイズと特性タブ、展開アライメントを含む関連プロパティを明らかにする図形のサイズを変更してテキストを修正するオプション。
グラフのデータ ラベルの形状をテキストに合わせてサイズ変更する
データ ラベルの形状をテキストに合わせてサイズ変更する Excel の機能を模倣するために、Aspose.Cells API は Boolean 型を公開しました。DataLabels.ResizeShapeToFitText財産。次のコードは、の単純な使用シナリオを示しています。DataLabels.ResizeShapeToFitText財産。
コードを実行する前のチャートは次のようになります。
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
// 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(ResizeChartDataLabelShapeToFitText.class); | |
// Create an instance of Workbook containing the Chart | |
Workbook book = new Workbook(dataDir + "report.xlsx"); | |
// Access the Worksheet that contains the Chart | |
Worksheet sheet = book.getWorksheets().get(0); | |
// Access ChartCollection from Worksheet | |
ChartCollection charts = sheet.getCharts(); | |
// Loop over each chart in collection | |
for (int chartIndex = 0; chartIndex < charts.getCount(); chartIndex++) { | |
// Access indexed chart from the collection | |
Chart chart = charts.get(chartIndex); | |
for (int seriesIndex = 0; seriesIndex < chart.getNSeries().getCount(); seriesIndex++) { | |
// Access the DataLabels of indexed NSeries | |
DataLabels labels = chart.getNSeries().get(seriesIndex).getDataLabels(); | |
// Set ResizeShapeToFitText property to true | |
labels.setResizeShapeToFitText(true); | |
} | |
// Calculate Chart | |
chart.calculate(); | |
} | |
// Save the result | |
book.save(dataDir + "output.xlsx"); |
コードを実行すると、チャートは次のようになります。