ワークシート内のコメントまたは図形の余白を設定する
可能な使用シナリオ
Aspose.Cellsを使用して、任意の図形またはコメントの余白をShape.TextBody.TextAlignmentプロパティを使用して設定できます。このプロパティは、異なるプロパティ(TopMarginPt、LeftMarginPt、BottomMarginPt、RightMarginPtなど)を持つAspose.Cells.Drawing.Texts.ShapeTextAlignmentクラスのオブジェクトを返します。
ワークシート内のコメントまたは図形の余白を設定する
次のサンプルコードをご覧ください。二つの図形を含むサンプルエクセルファイルをロードし、コードでそれぞれの図形にアクセスし、それらの上部、左側、下部、右側の余白を設定します。コードによって生成された出力エクセルファイルと、出力エクセルファイルに対するコードの効果を示したスクリーンショットをご覧ください。
サンプルコード
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
//Load the sample Excel file | |
Workbook wb = new Workbook("sampleSetMarginsOfCommentOrShapeInsideTheWorksheet.xlsx"); | |
//Access first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
foreach (Shape sh in ws.Shapes) | |
{ | |
//Access the text alignment | |
Aspose.Cells.Drawing.Texts.ShapeTextAlignment txtAlign = sh.TextBody.TextAlignment; | |
//Set auto margin false | |
txtAlign.IsAutoMargin = false; | |
//Set the top, left, bottom and right margins | |
txtAlign.TopMarginPt = 10; | |
txtAlign.LeftMarginPt = 10; | |
txtAlign.BottomMarginPt = 10; | |
txtAlign.RightMarginPt = 10; | |
} | |
//Save the output Excel file | |
wb.Save("outputSetMarginsOfCommentOrShapeInsideTheWorksheet.xlsx"); |