チャートのデータラベルの形状をテキストに合わせるようにサイズ変更する
Contents
[
Hide
]
Excelアプリケーションでは、チャートのデータラベルのテキストに合わせて形状を変更するオプションが提供されており、これによりテキストが形状内に収まるように形状のサイズが拡大されます。
Microsoft Excelのインタフェース上で、チャートのデータラベルを選択して、フォーマットデータラベルメニューを右クリックします。サイズとプロパティタブで、配置を展開して、テキストに合わせて形状を変更オプションを含む関連プロパティを表示します。
このオプションはExcelインターフェイスで、チャートのデータラベルを選択して右クリックし、「Format DataLabels」メニューを選択することでアクセスできます。 サイズとプロパティタブで、リサイズされた形状に合わせるオプションを含む関連プロパティを表示するには、配置を展開します。
Aspose.Cells for .NETを使用したテキスト合わせオプションで、チャートのデータラベルの形状をテキストに合わせてサイズ変更する方法
Excelのデータラベルのサイズをテキストに合わせる機能を模倣するために、Aspose.Cells APIでは、ブール型DataLabels.IsResizeShapeToFitTextプロパティが公開されています。次のコード例は、DataLabels.IsResizeShapeToFitTextプロパティの簡単な使用シナリオを示しています。
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-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create an instance of Workbook containing the Chart | |
var book = new Workbook(dataDir + "source.xlsx"); | |
// Access the Worksheet that contains the Chart | |
var sheet = book.Worksheets[0]; | |
foreach (Chart chart in sheet.Charts) | |
{ | |
for (int index = 0; index < chart.NSeries.Count; index++) | |
{ | |
// Access the DataLabels of indexed NSeries | |
var labels = chart.NSeries[index].DataLabels; | |
// Set ResizeShapeToFitText property to true | |
labels.IsResizeShapeToFitText = true; | |
} | |
// Calculate Chart | |
chart.Calculate(); | |
} | |
// Save the result | |
book.Save(dataDir + "output_out.xlsx"); |