ワークシート内のコメントまたは図形の余白を設定する
Contents
[
Hide
]
可能な使用シナリオ
Aspose.Cellsを使用して、Shape.TextBody.TextAlignment プロパティを使用して任意の図形またはコメントの余白を設定できます。このプロパティは、上部、左部、下部、右部の余白を設定するために使用できるShapeTextAlignment クラスのオブジェクトを返します。
ワークシート内のコメントまたは図形の余白を設定する
次のサンプルコードをご覧ください。このコードは、2つの図形を含むsample Excel fileをロードし、その図形ごとに上部、左部、下部、右部の余白を設定します。コードで生成されたoutput Excel fileと、それに対するコードの効果を示すスクリーンショットを参照してください。
サンプルコード
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 | |
//Load the sample Excel file | |
Workbook wb = new Workbook("sampleSetMarginsOfCommentOrShapeInsideTheWorksheet.xlsx"); | |
//Access first worksheet | |
Worksheet ws = wb.getWorksheets().get(0); | |
for(int idx =0; idx<ws.getShapes().getCount(); idx++) | |
{ | |
//Access the shape | |
Shape sh = ws.getShapes().get(idx); | |
//Access the text alignment | |
ShapeTextAlignment txtAlign = sh.getTextBody().getTextAlignment(); | |
//Set auto margin false | |
txtAlign.setAutoMargin(false); | |
//Set the top, left, bottom and right margins | |
txtAlign.setTopMarginPt(10); | |
txtAlign.setLeftMarginPt(10); | |
txtAlign.setBottomMarginPt(10); | |
txtAlign.setRightMarginPt(10); | |
} | |
//Save the output Excel file | |
wb.save("outputSetMarginsOfCommentOrShapeInsideTheWorksheet.xlsx"); |