在工作表内设置评论或形状的边距
Contents
[
Hide
]
可能的使用场景
Aspose.Cells允许您使用 Shape.TextBody.TextAlignment 属性设置任何形状或评论的边距。该属性返回 ShapeTextAlignment 类的对象,该对象具有不同的属性,例如 TopMarginPt、LeftMarginPt、BottomMarginPt、RightMarginPt 等,可以用来设置顶部、左侧、底部和右侧边距。
设置工作表内批注或形状的边距
请参阅以下示例代码。它加载了包含两个形状的 示例excel文件。代码逐一访问形状并设置其顶部、左侧、底部和右侧边距。请查看代码生成的 输出excel文件 和屏幕截图显示代码对输出excel文件的影响。
示例代码
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"); |