كيفية تطبيق / تحديد محاذاة النص لمربع النص
يمكن أن تحسن مربعات النص تعبيرات وثائقنا ورسوماتنا ، وتطبيق تحاذية مختلفة لأجزاء مختلفة من مربع النص يمكن أن يساعد في تسليط الضوء على نقاط الاهتمام للقراء. ولكن المحاذاة الافتراضية لمربع النص لا تلبي كل احتياجاتنا. لهذا ، قد تحتاج إلى ضبط كل مربع نص لتلبية متطلباتك المستهدفة. إذا لم يكن لديك الكثير من كائنات مربع النص لتعديلها، فأنت محظوظ. إذا كان هناك الكثير من مربعات النص لضبطها، أعتقد أنك ستكون في مأزق. لا تقلق الآن، Aspose.Cells يوفر واجهة برمجية لتساعدك في فعل ذلك تماماً.
يطبق الكود النموذجي التالي تحديد محاذاة النص على مربع نص.
// 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 = ""; | |
File file = new File(dataDir); | |
if(!file.exists()) | |
file.mkdir(); | |
//Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
ShapeCollection shapes = workbook.getWorksheets().get(0).getShapes(); | |
//add a TextBox | |
Shape shape = shapes.addTextBox(2, 0, 2, 0, 50, 120); | |
shape.setText("This is a test."); | |
//set alignment | |
shape.setTextHorizontalAlignment(TextAlignmentType.CENTER); | |
shape.setTextVerticalAlignment(TextAlignmentType.CENTER); | |
//Save the excel file. | |
workbook.save(dataDir + "result.xlsx"); |
يمكنك أيضًا تغيير محاذاة النص داخل شكل مربع النص باستخدام النص HTML المناسب. الكود النموذجي التالي يطبق تحديد محاذاة النص على النص الجزئي داخل مربع النص.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// Intialize an object of the Workbook class to load template file | |
Workbook sourceWb = new Workbook("SampleTextboxExcel2016.xlsx"); | |
// Access the target textbox whose text is to be aligned | |
Shape sourceTextBox = sourceWb.getWorksheets().get(0).getShapes().get(0); | |
// Create and object of the target workbook | |
Workbook destWb = new Workbook(); | |
// Access first worksheet from the collection | |
Worksheet _sheet = destWb.getWorksheets().get(0); | |
// Create new textbox | |
TextBox _textBox = (TextBox)_sheet.getShapes().addShape(6,1, 0, 1, 0, 200, 200); | |
// Use Html string from a template file textbox | |
_textBox.setHtmlText(sourceTextBox.getHtmlText()); | |
// Save the workbook on disc | |
destWb.save("Output.xlsx"); |