إدارة الضوابط
مقدمة
يمكن للمطورين إضافة كائنات رسم مختلفة مثل مربعات النص وخانات الاختيار وأزرار الاختيار ومربعات التحرير والسرد والتسميات والأزرار والخطوط والمستطيلات والأقواس والأشكال البيضاوية وأشرطة التمرير ومربعات المجموعة وما إلى ذلك ، يوفر Aspose.Cells Aspose.Cells. كل الكائنات الرسومية. ومع ذلك ، هناك عدد قليل من الكائنات الرسومية أو الأشكال التي لم يتم دعمها بعد. قم بإنشاء هذه الكائنات الرسومية في جدول بيانات مصمم باستخدام Microsoft Excel ثم قم باستيراد جدول بيانات المصمم إلى Aspose.Cells. يسمح لك Aspose.Cells بتحميل هذه الكائنات الرسومية من جدول بيانات مصمم وكتابتها في ملف تم إنشاؤه.
إضافة عنصر تحكم مربع نص إلى ورقة العمل
تتمثل إحدى طرق التأكيد على المعلومات المهمة في التقرير في استخدام مربع نص. على سبيل المثال ، أضف نصًا لتمييز اسم الشركة أو للإشارة إلى المنطقة الجغرافية ذات أعلى مبيعات وما إلى ذلك. يوفر Aspose.Cells فئة TextBoxes ، المستخدمة لإضافة مربع نص جديد إلى المجموعة. هناك فئة أخرى ،مربع الكتابة، والذي يمثل مربع نص يستخدم لتحديد جميع أنواع الإعدادات. لها بعض الأعضاء المهمين:
- الgetTextFrame طريقة إرجاع أMsoTextFrame كائن يستخدم لضبط محتويات مربع النص.
- الوضع طريقة تحديد نوع الموضع.
- التعيين الخط تحدد الطريقة سمات الخط.
- الadd ارتباط تشعبي يضيف أسلوب ارتباط تشعبي لمربع النص.
- الملء إرجاع الممتلكاتتنسيق MsoFillFormat المستخدم لتعيين تنسيق التعبئة لمربع النص.
- التنسيق الخط خاصية إرجاع التنسيق MsoLine عادةً ما يتم استخدام الكائن في نمط سطر مربع النص ووزنه.
- النص مجموعة الأسلوب يحدد نص الإدخال لمربع النص.
يقوم المثال التالي بإنشاء مربعين نصيين في ورقة العمل الأولى من المصنف. تم تجهيز مربع النص الأول جيدًا بإعدادات تنسيق مختلفة. والثاني بسيط.
يتم إنشاء المخرجات التالية عن طريق تنفيذ الكود:
يتم إنشاء مربعي نص في ورقة العمل
// 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 = Utils.getSharedDataDir(AddingTextBoxControl.class) + "DrawingObjects/"; | |
// Instantiate a new Workbook. | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet in the book. | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Get the textbox object. | |
int textboxIndex = worksheet.getTextBoxes().add(2, 1, 160, 200); | |
TextBox textbox0 = worksheet.getTextBoxes().get(textboxIndex); | |
// Fill the text. | |
textbox0.setText("ASPOSE______The .NET & JAVA Component Publisher!"); | |
// Set the placement. | |
textbox0.setPlacement(PlacementType.FREE_FLOATING); | |
// Set the font color. | |
textbox0.getFont().setColor(Color.getBlue()); | |
// Set the font to bold. | |
textbox0.getFont().setBold(true); | |
// Set the font size. | |
textbox0.getFont().setSize(14); | |
// Set font attribute to italic. | |
textbox0.getFont().setItalic(true); | |
// Add a hyperlink to the textbox. | |
textbox0.addHyperlink("http://www.aspose.com/"); | |
// Get the filformat of the textbox. | |
FillFormat fillformat = textbox0.getFill(); | |
// Set the fillcolor. | |
fillformat.setOneColorGradient(Color.getSilver(), 1, GradientStyleType.HORIZONTAL, 1); | |
// Get the lineformat type of the textbox. | |
LineFormat lineformat = textbox0.getLine(); | |
// Set the line style. | |
lineformat.setDashStyle(MsoLineStyle.THIN_THICK); | |
// Set the line weight. | |
lineformat.setWeight(6); | |
// Set the dash style to squaredot. | |
lineformat.setDashStyle(MsoLineDashStyle.SQUARE_DOT); | |
// Get the second textbox. | |
TextBox textbox1 = (com.aspose.cells.TextBox) worksheet.getShapes().addShape(MsoDrawingType.TEXT_BOX, 15, 0, 4, | |
0, 85, 120); | |
// Input some text to it. | |
textbox1.setText("This is another simple text box"); | |
// Set the placement type as the textbox will move and resize with cells. | |
textbox1.setPlacement(PlacementType.MOVE_AND_SIZE); | |
// Save the excel file. | |
workbook.save(dataDir + "AddingTextBoxControl_out.xls"); |
معالجة عناصر تحكم مربع النص في جداول بيانات المصمم
يتيح لك Aspose.Cells أيضًا الوصول إلى مربعات النص في أوراق عمل المصمم ومعالجتها. استخدم الWorksheet.getTextBoxes للحصول على مجموعة مربعات النص في الورقة.
يستخدم المثال التالي ملف Microsoft Excel - tsttextboxes.xls - الذي أنشأناه في المثال أعلاه. يحصل على السلاسل النصية لمربعي النص ويغير نص مربع النص الثاني لحفظ الملف.
// 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 = Utils.getDataDir(ManipulatingTextBoxControls.class); | |
// Instantiate a new Workbook. | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Get the first worksheet in the book. | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Get the first textbox object. | |
com.aspose.cells.TextBox textbox0 = worksheet.getTextBoxes().get(0); | |
// Obtain the text in the first textbox. | |
String text0 = textbox0.getText(); | |
System.out.println(text0); | |
// Get the second textbox object. | |
com.aspose.cells.TextBox textbox1 = worksheet.getTextBoxes().get(1); | |
// Obtain the text in the second textbox. | |
String text1 = textbox1.getText(); | |
// Change the text of the second textbox. | |
textbox1.setText("This is an alternative text"); | |
// Save the excel file. | |
workbook.save(dataDir + "tsttextboxes1.xls"); |
إضافة عنصر تحكم CheckBox إلى ورقة العمل
تكون خانات الاختيار سهلة الاستخدام إذا كنت تريد توفير طريقة للمستخدم للاختيار بين خيارين ، مثل صواب أو خطأ ؛ نعم أو لا. Aspose.Cells يسمح لك باستخدام مربعات الاختيار في أوراق العمل. على سبيل المثال ، ربما تكون قد طورت ورقة عمل الإسقاط المالي حيث يمكنك إما حساب عملية استحواذ معينة أم لا. في هذه الحالة ، قد ترغب في وضع خانة اختيار أعلى ورقة العمل. يمكنك بعد ذلك ربط حالة خانة الاختيار هذه بخلية أخرى ، بحيث إذا تم تحديد خانة الاختيار ، فإن قيمة الخلية هي True ؛ إذا لم يتم تحديدها ، فإن قيمة الخلية هي False.
باستخدام Microsoft إكسل
لوضع عنصر تحكم خانة اختيار في ورقة العمل الخاصة بك ، اتبع الخطوات التالية:
- تأكد من عرض شريط أدوات النماذج.
- انقر علىخانة اختيار أداة على شريط أدوات النماذج.
- في منطقة ورقة العمل الخاصة بك ، انقر واسحب لتحديد المستطيل الذي سيحتفظ بخانة الاختيار والتسمية بجانب خانة الاختيار.
- بمجرد وضع مربع الاختيار ، حرك مؤشر الماوس إلى منطقة الملصق وقم بتغيير التسمية.
- في الCell رابط، حدد عنوان الخلية التي يجب ربط خانة الاختيار هذه بها.
- انقر فوقنعم.
باستخدام Aspose.Cells
يوفر Aspose.Cells ملفCheckBoxCollection class ، والتي تُستخدم لإضافة خانة اختيار جديدة إلى المجموعة. هناك فئة أخرى ،Aspose.Cells.Drawing.CheckBox، والذي يمثل خانة اختيار. لها بعض الأعضاء المهمين:
- الsetLinkedCell الطريقة تحدد خلية مرتبطة بخانة الاختيار.
- النص مجموعة تحدد الطريقة السلسلة النصية المرتبطة بخانة الاختيار. إنها تسمية خانة الاختيار.
- الsetValue تحدد الطريقة إذا تم تحديد خانة الاختيار أم لا.
يوضح المثال التالي كيفية إضافة خانة اختيار إلى ورقة العمل. يتم إنشاء الإخراج أدناه بعد تنفيذ الكود.
تمت إضافة CheckBox في ورقة العمل
// 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 = Utils.getDataDir(AddingCheckBoxControl.class); | |
// Instantiate a new Workbook. | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet in the book. | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Add a checkbox to the first worksheet in the workbook. | |
int checkBoxIndex = worksheet.getCheckBoxes().add(5, 5, 100, 120); | |
CheckBox checkBox = worksheet.getCheckBoxes().get(checkBoxIndex); | |
// Set its text string. | |
checkBox.setText("Check it!"); | |
// Put a value into B1 cell. | |
worksheet.getCells().get("B1").setValue("LnkCell"); | |
// Set B1 cell as a linked cell for the checkbox. | |
checkBox.setLinkedCell("=B1"); | |
// Save the excel file. | |
workbook.save(dataDir + "tstcheckboxes.xls"); |
إضافة عنصر تحكم RadioButton إلى ورقة العمل
زر الاختيار ، أو زر الخيار ، هو عنصر تحكم مصنوع من صندوق دائري. يتخذ المستخدم قراره عن طريق تحديد المربع الدائري. عادة ما يكون زر الاختيار مصحوبًا بآخرين ، إن لم يكن دائمًا. تظهر أزرار الاختيار هذه وتتصرف كمجموعة. يقرر المستخدم أي زر يكون صالحًا عن طريق اختيار زر واحد فقط. عندما ينقر المستخدم على زر واحد ، يتم ملؤه. عند تحديد زر واحد في المجموعة ، تكون أزرار المجموعة نفسها فارغة.
باستخدام Microsoft إكسل
لوضع عنصر تحكم زر راديو في ورقة العمل الخاصة بك ، اتبع الخطوات التالية:
- تأكد من أننماذج يتم عرض شريط الأدوات.
- انقر علىزر الخيارات أداة.
- في ورقة العمل ، انقر واسحب لتحديد المستطيل الذي سيحتفظ بزر الخيار والتسمية بجانب زر الخيار.
- بمجرد وضع زر الاختيار في ورقة العمل ، حرك مؤشر الماوس إلى منطقة التسمية وقم بتغيير التسمية.
- في الCell رابط ، حدد عنوان الخلية التي يجب أن يرتبط بها زر الاختيار هذا.
- انقرنعم.
باستخدام Aspose.Cells
الShapeCollectionتوفر class طريقة تسمى addShape والتي يمكن استخدامها لإضافة عنصر تحكم زر اختيار إلى ورقة العمل. قد تعيد الطريقة كائن RadioButton. تمثل فئة RadioButton زر خيار. لها بعض الأعضاء المهمين:
- تحدد طريقة setLinkedCell خلية مرتبطة بزر الاختيار.
- تحدد طريقة setText السلسلة النصية المرتبطة بزر الاختيار. إنها تسمية زر الاختيار.
- تحدد الخاصية Checked ما إذا كان زر الاختيار محددًا أم لا.
- تحدد طريقة setFillFormat تنسيق تعبئة زر الاختيار.
- تحدد طريقة setLineFormat أنماط تنسيق الخط لزر الخيار.
يوضح المثال التالي كيفية إضافة أزرار اختيار إلى ورقة عمل. يضيف المثال ثلاثة أزرار اختيار تمثل الفئات العمرية. سيتم إنشاء الإخراج التالي بعد تنفيذ الكود.
تتم إضافة بعض RadioButtons في ورقة العمل
إضافة عنصر تحكم مربع التحرير والسرد إلى ورقة عمل
لتسهيل إدخال البيانات ، أو لتقييد الإدخالات بعناصر معينة تحددها ، يمكنك إنشاء مربع تحرير وسرد أو قائمة منسدلة للإدخالات الصالحة التي تم تجميعها من خلايا في مكان آخر بورقة العمل. عند إنشاء قائمة منسدلة لخلية ، فإنها تعرض سهمًا بجوار تلك الخلية. لإدخال معلومات في تلك الخلية ، انقر فوق السهم ، ثم انقر فوق الإدخال الذي تريده.
باستخدام Microsoft إكسل
لوضع عنصر تحكم مربع تحرير وسرد في ورقة العمل الخاصة بك ، اتبع الخطوات التالية:
- تأكد من أننماذج يتم عرض شريط الأدوات.
- اضغط علىصندوق التحرير أداة.
- في منطقة ورقة العمل الخاصة بك ، انقر واسحب لتحديد المستطيل الذي سيحتوي على مربع التحرير والسرد.
- بمجرد وضع مربع التحرير والسرد في ورقة العمل ، انقر بزر الماوس الأيمن فوق عنصر التحكم للنقرتنسيق التحكم وحدد نطاق الإدخال.
- في الCell رابط ، حدد عنوان الخلية التي يجب ربط مربع التحرير والسرد بها.
- انقر فوقنعم.
باستخدام Aspose.Cells
الShapeCollectionتوفر class طريقة تسمى addShape ، والتي يمكن استخدامها لإضافة عنصر تحكم مربع تحرير وسرد إلى ورقة العمل. يمكن للأسلوب إرجاع كائن ComboBox. تمثل فئة ComboBox مربع تحرير وسرد. لها بعض الأعضاء المهمين:
- تحدد طريقة setLinkedCell خلية مرتبطة بمربع التحرير والسرد.
- تحدد طريقة setInputRange نطاق خلايا ورقة العمل المستخدمة لتعبئة مربع التحرير والسرد.
- تحدد طريقة setDropDownLines عدد أسطر القائمة المعروضة في الجزء المنسدل من مربع التحرير والسرد.
- تشير طريقة setShadow إلى ما إذا كان مربع التحرير والسرد به تظليل ثلاثي الأبعاد.
يوضح المثال التالي كيفية إضافة مربع تحرير وسرد إلى ورقة العمل. يتم إنشاء الإخراج التالي عند تنفيذ التعليمات البرمجية.
تتم إضافة مربع تحرير وسرد في ورقة العمل
// 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 = Utils.getDataDir(AddingComboBoxControl.class); | |
// Create a new Workbook. | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet. | |
Worksheet sheet = workbook.getWorksheets().get(0); | |
// Get the worksheet cells collection. | |
Cells cells = sheet.getCells(); | |
// Input a value. | |
cells.get("B3").setValue("Employee:"); | |
Style style = cells.get("B3").getStyle(); | |
style.getFont().setBold(true); | |
// Set it bold. | |
cells.get("B3").setStyle(style); | |
// Input some values that denote the input range for the combo box. | |
cells.get("A2").setValue("Emp001"); | |
cells.get("A3").setValue("Emp002"); | |
cells.get("A4").setValue("Emp003"); | |
cells.get("A5").setValue("Emp004"); | |
cells.get("A6").setValue("Emp005"); | |
cells.get("A7").setValue("Emp006"); | |
// Add a new combo box. | |
com.aspose.cells.ComboBox comboBox = (com.aspose.cells.ComboBox) sheet.getShapes() | |
.addShape(MsoDrawingType.COMBO_BOX, 3, 0, 1, 0, 20, 100); | |
// Set the linked cell; | |
comboBox.setLinkedCell("A1"); | |
// Set the input range. | |
comboBox.setInputRange("=A2:A7"); | |
// Set no. of list lines displayed in the combo box's list portion. | |
comboBox.setDropDownLines(5); | |
// Set the combo box with 3-D shading. | |
comboBox.setShadow(true); | |
// AutoFit Columns | |
sheet.autoFitColumns(); | |
// Saves the file. | |
workbook.save(dataDir + "tstcombobox.xls"); |
إضافة عنصر تحكم التسمية إلى ورقة عمل
الملصقات هي وسيلة لمنح المستخدمين معلومات حول محتويات جدول البيانات. يتيح Aspose.Cells إضافة ومعالجة التسميات في ورقة العمل. الShapeCollectionتوفر class طريقة تسمى addShape ، تُستخدم لإضافة عنصر تحكم تسمية إلى ورقة العمل. تقوم الطريقة بإرجاع كائن Label. تمثل تسمية الفئة تسمية في ورقة العمل. لها بعض الأعضاء المهمين:
- تحدد طريقة setText سلسلة التسمية التوضيحية الخاصة بالتسمية.
- تحدد طريقة setPlacement PlacementType ، وهي الطريقة التي يتم بها إرفاق التسمية بالخلايا في ورقة العمل.
يوضح المثال التالي كيفية إضافة تسمية إلى ورقة العمل. يتم إنشاء الإخراج التالي عند تنفيذ التعليمات البرمجية.
تتم إضافة تسمية في ورقة العمل
// 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 = Utils.getSharedDataDir(AddingLabelControl.class) + "DrawingObjects/"; | |
// Create a new Workbook. | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet. | |
Worksheet sheet = workbook.getWorksheets().get(0); | |
// Add a new label to the worksheet. | |
com.aspose.cells.Label label = (com.aspose.cells.Label) sheet.getShapes().addShape(MsoDrawingType.LABEL, 2, 2, | |
2, 0, 60, 120); | |
// Set the caption of the label. | |
label.setText("This is a Label"); | |
// Set the Placement Type, the way the label is attached to the cells. | |
label.setPlacement(PlacementType.FREE_FLOATING); | |
// Set the fill color of the label. | |
label.getFill().setOneColorGradient(Color.getYellow(), 1, GradientStyleType.HORIZONTAL, 1); | |
// Saves the file. | |
workbook.save(dataDir + "AddingLabelControl_out.xls"); |
إضافة عنصر تحكم مربع قائمة إلى ورقة عمل
ينشئ عنصر تحكم مربع القائمة عنصر تحكم قائمة يسمح بتحديد عنصر واحد أو عدة عناصر.
باستخدام Microsoft إكسل
لوضع عنصر تحكم مربع قائمه في ورقه عمل:
- تأكد من أننماذج يتم عرض شريط الأدوات.
- اضغط علىمربع القائمة أداة.
- في منطقة ورقة العمل الخاصة بك ، انقر واسحب لتحديد المستطيل الذي سيحتوي على مربع القائمة.
- بمجرد وضع مربع القائمة في ورقة العمل ، انقر بزر الماوس الأيمن فوق عنصر التحكم للنقرتنسيق التحكم وحدد نطاق الإدخال.
- في الCell رابط، حدد عنوان الخلية التي يجب ربط مربع القائمة هذا بها وقم بتعيين نوع التحديد (فردي ، متعدد ، ممتد)
- انقرنعم.
باستخدام Aspose.Cells
الShapeCollection توفر class طريقة تسمى addShape ، والتي تُستخدم لإضافة عنصر تحكم مربع قائمة إلى ورقة عمل. تقوم الطريقة بإرجاع كائن ListBox. يمثل ListBox للفئة مربع قائمة. لها بعض الأعضاء المهمين:
- تحدد طريقة setLinkedCell خلية مرتبطة بمربع القائمة.
- تحدد طريقة setInputRange نطاق خلايا ورقة العمل المستخدمة لملء مربع القائمة.
- تحدد طريقة setSelectionType وضع التحديد لمربع القائمة.
- تشير طريقة setShadow إلى ما إذا كان مربع القائمة به تظليل ثلاثي الأبعاد.
يوضح المثال التالي كيفية إضافة مربع قائمة إلى ورقة العمل. يتم إنشاء الإخراج التالي عند تنفيذ التعليمات البرمجية.
تمت إضافة مربع قائمة في ورقة العمل
// 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 = Utils.getDataDir(AddingListBoxControl.class); | |
// Create a new Workbook. | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet. | |
Worksheet sheet = workbook.getWorksheets().get(0); | |
// Get the worksheet cells collection. | |
Cells cells = sheet.getCells(); | |
// Input a value. | |
cells.get("B3").setValue("Choose Dept:"); | |
Style style = cells.get("B3").getStyle(); | |
style.getFont().setBold(true); | |
// Set it bold. | |
cells.get("B3").setStyle(style); | |
// Input some values that denote the input range for the combo box. | |
cells.get("A2").setValue("Sales"); | |
cells.get("A3").setValue("Finance"); | |
cells.get("A4").setValue("MIS"); | |
cells.get("A5").setValue("R&D"); | |
cells.get("A6").setValue("Marketing"); | |
cells.get("A7").setValue("HRA"); | |
// Add a new list box. | |
com.aspose.cells.ListBox listBox = (com.aspose.cells.ListBox) sheet.getShapes() | |
.addShape(MsoDrawingType.LIST_BOX, 3, 3, 1, 0, 100, 122); | |
// Set the linked cell; | |
listBox.setLinkedCell("A1"); | |
// Set the input range. | |
listBox.setInputRange("=A2:A7"); | |
// Set the Placement Type, the way the list box is attached to the cells. | |
listBox.setPlacement(PlacementType.FREE_FLOATING); | |
// Set the list box with 3-D shading. | |
listBox.setShadow(true); | |
// Set the selection type. | |
listBox.setSelectionType(SelectionType.SINGLE); | |
// AutoFit Columns | |
sheet.autoFitColumns(); | |
// Saves the file. | |
workbook.save(dataDir + "tstlistbox.xls"); |
إضافة زر التحكم إلى ورقة عمل
الأزرار مفيدة لأداء بعض الإجراءات. في بعض الأحيان ، يكون من المفيد تعيين VBA Macro للزر أو تعيين ارتباط تشعبي لفتح صفحة ويب.
باستخدام Microsoft إكسل
لوضع عنصر تحكم زر في ورقة العمل الخاصة بك:
- تأكد من أننماذج يتم عرض شريط الأدوات.
- اضغط علىزر أداة.
- في منطقة ورقة العمل الخاصة بك ، انقر واسحب لتحديد المستطيل الذي سيحتفظ بالزر.
- بمجرد وضع مربع القائمة في ورقة العمل ، انقر بزر الماوس الأيمن فوق عنصر التحكم وحددتنسيق التحكم، ثم حدد VBA Macro والسمات ذات الصلة بالخط والمحاذاة والحجم والهامش وما إلى ذلك.
- انقر فوقنعم.
باستخدام Aspose.Cells
الShapeCollection توفر class طريقة تسمى addShape ، تُستخدم لإضافة عنصر تحكم زر إلى ورقة العمل. قد ترجع الطريقة كائن زر. يمثل زر الفصل زرًا. لها بعض الأعضاء المهمين:
- تحدد طريقة setText تسمية الزر.
- تحدد طريقة setPlacement PlacementType ، وهي الطريقة التي يتم بها إرفاق الزر بالخلايا في ورقة العمل.
- يضيف أسلوب addHyperlink ارتباطًا تشعبيًا لعنصر تحكم الزر. سيؤدي النقر فوق الزر إلى الانتقال إلى عنوان URL ذي الصلة.
يوضح المثال التالي كيفية إضافة زر إلى ورقة العمل. يتم إنشاء الإخراج التالي عند تنفيذ التعليمات البرمجية
يضاف زر في ورقة العمل
إضافة عنصر تحكم الخط إلى ورقة عمل
Aspose.Cells يسمح لك برسم أشكال تلقائية في أوراق العمل الخاصة بك. يمكنك إنشاء خط بسهولة. يُسمح لك أيضًا بتنسيق الخط. على سبيل المثال ، يمكنك تغيير لون الخط وتحديد وزن الخط ونمطه حسب حاجتك.
باستخدام Microsoft إكسل
- على الرسم شريط الأدوات ، انقر فوقأشكال تلقائية ، يشير إلىخطوط، وحدد نمط الخط الذي تريده.
- اسحب لرسم الخط.
- قم بأحد الإجراءين التاليين أو كليهما:
- لتقييد الخط بالرسم بزاوية 15 درجة من نقطة البداية ، اضغط باستمرار على المفتاح SHIFT أثناء السحب.
- لإطالة الخط في اتجاهين متعاكسين من نقطة النهاية الأولى ، اضغط باستمرار على CTRL أثناء السحب.
باستخدام Aspose.Cells
الShapeCollectionتوفر class طريقة تسمى addShape ، والتي تُستخدم لإضافة شكل خط إلى ورقة العمل. قد ترجع الطريقة كائن LineShape. يمثل LineShape الفئة سطرًا. لها بعض الأعضاء المهمين:
- تحدد طريقة setDashStyle تنسيق الخط.
- تحدد طريقة setPlacement PlacementType ، وهي الطريقة التي يتم بها إرفاق الخط بالخلايا في ورقة العمل.
يوضح المثال التالي كيفية إضافة أسطر إلى ورقة العمل. يقوم بإنشاء ثلاثة خطوط بأنماط مختلفة. يتم إنشاء الإخراج التالي بعد تنفيذ الكود
تمت إضافة بضعة أسطر في ورقة العمل
// 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 = Utils.getSharedDataDir(AddingLineControl.class) + "DrawingObjects/"; | |
//Instantiate a new Workbook. | |
Workbook workbook = new Workbook(); | |
//Get the first worksheet in the book. | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
//Add a new line to the worksheet. | |
LineShape line1 = (LineShape)worksheet.getShapes().addShape(MsoDrawingType.LINE,5, 1,0,0, 0, 250); | |
line1.setHasLine(true); | |
//Set the line dash style | |
LineFormat shapeline = line1.getLine(); | |
shapeline.setDashStyle(MsoLineDashStyle.SOLID); | |
//Set the placement. | |
line1.setPlacement(PlacementType.FREE_FLOATING); | |
//Add another line to the worksheet. | |
LineShape line2 = (LineShape) worksheet.getShapes().addShape(MsoDrawingType.LINE, 7, 1,0,0, 85, 250); | |
line2.setHasLine(true); | |
//Set the line dash style. | |
shapeline = line2.getLine(); | |
shapeline.setDashStyle(MsoLineDashStyle.DASH_LONG_DASH); | |
shapeline.setWeight(4); | |
//Set the placement. | |
line2.setPlacement(PlacementType.FREE_FLOATING); | |
//Add the third line to the worksheet. | |
LineShape line3 = (LineShape)worksheet.getShapes().addShape(MsoDrawingType.LINE, 13, 1,0,0, 0, 250); | |
line3.setHasLine(true); | |
//Set the line dash style | |
shapeline = line1.getLine(); | |
shapeline.setDashStyle(MsoLineDashStyle.SOLID); | |
//Set the placement. | |
line3.setPlacement(PlacementType.FREE_FLOATING); | |
//Save the excel file. | |
workbook.save(dataDir + "tstlines.xls"); |
إضافة رأس سهم إلى خط
يسمح لك 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 = Utils.getSharedDataDir(AddinganArrowHead.class) + "DrawingObjects/"; | |
//Instantiate a new Workbook. | |
Workbook workbook = new Workbook(); | |
//Get the first worksheet in the book. | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
//Add a line to the worksheet | |
LineShape line2 = (LineShape) worksheet.getShapes().addShape(MsoDrawingType.LINE, 7, 0, 1, 0, 85, 250); | |
//Set the line color | |
line2.getLine().setFillType(FillType.SOLID); | |
line2.getLine().getSolidFill().setColor(Color.getRed()); | |
//Set the weight of the line. | |
line2.getLine().setWeight(3); | |
//Set the placement. | |
line2.setPlacement(PlacementType.FREE_FLOATING); | |
//Set the line arrows. | |
line2.getLine().setEndArrowheadWidth(MsoArrowheadWidth.MEDIUM); | |
line2.getLine().setEndArrowheadStyle(MsoArrowheadStyle.ARROW); | |
line2.getLine().setEndArrowheadLength(MsoArrowheadLength.MEDIUM); | |
line2.getLine().setBeginArrowheadStyle(MsoArrowheadStyle.ARROW_DIAMOND); | |
line2.getLine().setBeginArrowheadLength(MsoArrowheadLength.MEDIUM); | |
//Make the gridlines invisible in the first worksheet. | |
workbook.getWorksheets().get(0).setGridlinesVisible(false); | |
//Save the excel file. | |
workbook.save(dataDir + "AddinganArrowHead_out.xlsx"); |
إضافة عنصر تحكم مستطيل إلى ورقة عمل
يسمح لك Aspose.Cells برسم أشكال مستطيلة في أوراق العمل الخاصة بك. يمكنك إنشاء مستطيل أو مربع وما إلى ذلك. يُسمح لك أيضًا بتنسيق لون التعبئة ولون خط الحدود لعنصر التحكم. على سبيل المثال ، يمكنك تغيير لون المستطيل وتعيين لون التظليل وتحديد وزن المستطيل ونمطه حسب حاجتك.
باستخدام Microsoft إكسل
- على الرسم شريط الأدوات ، انقر فوقمستطيل.
- اسحب لرسم المستطيل.
- قم بأحد الإجراءين التاليين أو كليهما:
- لتقييد المستطيل برسم مربع من نقطة البداية ، اضغط باستمرار على المفتاح SHIFT أثناء السحب.
- لرسم مستطيل من نقطة مركزية ، اضغط باستمرار على CTRL أثناء السحب.
باستخدام Aspose.Cells
الShapeCollection توفر class طريقة تسمى addShape ، تُستخدم لإضافة شكل مستطيل إلى ورقة العمل. يمكن للطريقة إرجاع كائن RectangleShape. تمثل الفئة RectangleShape مستطيلاً. لها بعض الأعضاء المهمين:
- تحدد طريقة setLineFormat سمات تنسيق الخط للمستطيل.
- تحدد طريقة setPlacement PlacementType ، وهي الطريقة التي يتم بها إرفاق المستطيل بالخلايا في ورقة العمل.
- تحدد الخاصية FillFormat أنماط تنسيق التعبئة لمستطيل.
يوضح المثال التالي كيفية إضافة مستطيل إلى ورقة العمل. يتم إنشاء الإخراج التالي عند تنفيذ التعليمات البرمجية.
يتم إضافة مستطيل في ورقة العمل
// 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 = Utils.getSharedDataDir(AddingRectangleControl.class) + "DrawingObjects/"; | |
// Instantiate a new Workbook. | |
Workbook excelbook = new Workbook(); | |
// Add a rectangle control. | |
com.aspose.cells.RectangleShape rectangle = (com.aspose.cells.RectangleShape) excelbook.getWorksheets().get(0) | |
.getShapes().addShape(MsoDrawingType.RECTANGLE, 3, 2, 0, 0, 70, 130); | |
// Set the placement of the rectangle. | |
rectangle.setPlacement(PlacementType.FREE_FLOATING); | |
// Set the fill format. | |
FillFormat fillformat = rectangle.getFill(); | |
fillformat.setOneColorGradient(Color.getOlive(), 1, GradientStyleType.HORIZONTAL, 1); | |
// Set the line style. | |
LineFormat linestyle = rectangle.getLine(); | |
linestyle.setDashStyle(MsoLineStyle.THICK_THIN); | |
// Set the line weight. | |
linestyle.setWeight(4); | |
// Set the color of the line. | |
linestyle.setOneColorGradient(Color.getBlue(), 1, GradientStyleType.HORIZONTAL, 1); | |
// Set the dash style of the rectangle. | |
linestyle.setDashStyle(MsoLineDashStyle.SOLID); | |
// Save the excel file. | |
excelbook.save(dataDir + "AddingRectangleControl_out.xls"); |
إضافة عنصر تحكم القوس إلى ورقة العمل
Aspose.Cells يسمح لك برسم أشكال قوس في أوراق العمل الخاصة بك. يمكنك إنشاء أقواس بسيطة ومليئة. يُسمح لك بتنسيق لون التعبئة ولون خط الحدود لعنصر التحكم. على سبيل المثال ، يمكنك تحديد / تغيير لون القوس ، وتعيين لون التظليل ، وتحديد وزن الشكل ونمطه حسب حاجتك.
باستخدام Microsoft إكسل
- على الرسم شريط الأدوات ، انقر فوققوس في الأشكال تلقائية.
- اسحب لرسم القوس.
باستخدام Aspose.Cells
الShapeCollection توفر class طريقة تسمى addShape ، تُستخدم لإضافة شكل قوس إلى ورقة العمل. يمكن للطريقة إرجاع كائن ArcShape. تمثل فئة ArcShape قوسًا. لها بعض الأعضاء المهمين:
- تحدد طريقة setLineFormat سمات تنسيق الخط لشكل القوس.
- تحدد طريقة setPlacement PlacementType ، وهي الطريقة التي يتم بها ربط القوس بالخلايا في ورقة العمل.
- تحدد الخاصية FillFormat أنماط تنسيق التعبئة للشكل.
يوضح المثال التالي كيفية إضافة أشكال قوس إلى ورقة العمل. ينشئ المثال شكلين قوسين: أحدهما ممتلئ والآخر بسيط. يتم إنشاء الإخراج التالي عند تنفيذ التعليمات البرمجية
تتم إضافة شكلين قوسين إلى ورقة العمل
// 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 = Utils.getSharedDataDir(AddingArcControl.class) + "DrawingObjects/"; | |
// Instantiate a new Workbook. | |
Workbook excelbook = new Workbook(); | |
// Add an arc shape. | |
com.aspose.cells.ArcShape arc1 = (com.aspose.cells.ArcShape) excelbook.getWorksheets().get(0).getShapes() | |
.addShape(MsoDrawingType.ARC, 2, 2, 0, 0, 130, 130); | |
// Set the placement of the arc. | |
arc1.setPlacement(PlacementType.FREE_FLOATING); | |
// Set the fill format. | |
FillFormat fillformat = arc1.getFill();// getFillFormat(); | |
fillformat.setOneColorGradient(Color.getLime(), 1, GradientStyleType.HORIZONTAL, 1); | |
//setForeColor(Color.getBlue()); | |
// Set the line style. | |
LineFormat lineformat = arc1.getLine();// getLineFormat(); | |
lineformat.setDashStyle(MsoLineStyle.SINGLE); //setStyle(MsoLineStyle.SINGLE); | |
// Set the line weight. | |
lineformat.setWeight(1); | |
// Set the color of the arc line. | |
lineformat.setOneColorGradient(Color.getLime(), 1, GradientStyleType.HORIZONTAL, 1); //setForeColor(Color.getBlue()); | |
// Set the dash style of the arc. | |
lineformat.setDashStyle(MsoLineDashStyle.SOLID); | |
// Add another arc shape. | |
com.aspose.cells.ArcShape arc2 = (com.aspose.cells.ArcShape) excelbook.getWorksheets().get(0).getShapes() | |
.addShape(MsoDrawingType.ARC, 9, 2, 0, 0, 130, 130); | |
// Set the placement of the arc. | |
arc2.setPlacement(PlacementType.FREE_FLOATING); | |
// Set the line style. | |
LineFormat lineformat1 = arc2.getLine(); //getLineFormat(); | |
lineformat1.setDashStyle(MsoLineStyle.SINGLE); | |
// Set the line weight. | |
lineformat1.setWeight(1); | |
// Set the color of the arc line. | |
lineformat1.setOneColorGradient(Color.getLime(), 1, GradientStyleType.HORIZONTAL, 1);//setForeColor(Color.getBlue()); | |
// Set the dash style of the arc. | |
lineformat1.setDashStyle(MsoLineDashStyle.SOLID); | |
// Save the excel file. | |
excelbook.save(dataDir + "AddingArcControl_out.xls"); |
إضافة تحكم بيضاوي إلى ورقة عمل
Aspose.Cells يسمح لك برسم أشكال بيضاوية في أوراق العمل. قم بإنشاء أشكال بيضاوية بسيطة ومعبأة وقم بتنسيق لون التعبئة ولون خط الحدود لعنصر التحكم. على سبيل المثال ، يمكنك تحديد / تغيير لون الشكل البيضاوي ، وتعيين لون التظليل ، وتحديد وزن الشكل ونمطه.
باستخدام Microsoft إكسل
- على الرسم شريط الأدوات ، انقر فوقبيضاوي .
- اسحب لرسم الشكل البيضاوي.
- قم بأحد الإجراءين التاليين أو كليهما:
- لتقييد الشكل البيضاوي لرسم دائرة من نقطة البداية ، اضغط باستمرار على المفتاح SHIFT أثناء السحب.
- لرسم شكل بيضاوي من نقطة مركزية ، اضغط باستمرار على CTRL أثناء السحب.
باستخدام Aspose.Cells
الShapeCollection توفر class طريقة تسمى addShape ، تُستخدم لإضافة شكل بيضاوي إلى ورقة العمل. قد ترجع الطريقة كائنًا بيضاويًا. يمثل الفصل البيضاوي شكلًا بيضاويًا. لها بعض الأعضاء المهمين:
- تحدد طريقة setLineFormat سمات تنسيق الخط للشكل البيضاوي.
- تحدد طريقة setPlacement الملفنوع الموضع ، طريقة إرفاق الشكل البيضاوي بالخلايا في ورقة العمل.
- تحدد الخاصية FillFormat أنماط تنسيق التعبئة للشكل.
يوضح المثال التالي كيفية إضافة أشكال بيضاوية إلى ورقة العمل. ينشئ المثال شكلين بيضاويين: أحدهما مملوء بشكل بيضاوي والآخر عبارة عن دائرة بسيطة. يتم إنشاء الإخراج التالي عند تنفيذ التعليمات البرمجية.
تمت إضافة شكلين بيضاويين في ورقة العمل
// 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 = Utils.getSharedDataDir(AddinganOvalControl.class) + "DrawingObjects/"; | |
// Instantiate a new Workbook. | |
Workbook excelbook = new Workbook(); | |
// Add an oval shape. | |
Oval oval1 = (com.aspose.cells.Oval) excelbook.getWorksheets().get(0).getShapes().addShape(MsoDrawingType.OVAL, | |
2, 2, 0, 0, 130, 130); | |
// Set the placement of the oval. | |
oval1.setPlacement(PlacementType.FREE_FLOATING); | |
// Set the fill format. | |
FillFormat fillformat = oval1.getFill();// getFillFormat(); | |
fillformat.setOneColorGradient(Color.getNavy(), 1, GradientStyleType.HORIZONTAL, 1); | |
// Set the line style. | |
LineFormat lineformat = oval1.getLine();// getLineFormat(); | |
lineformat.setDashStyle(MsoLineStyle.SINGLE); //setStyle(MsoLineStyle.SINGLE); | |
// Set the line weight. | |
lineformat.setWeight(1); | |
// Set the color of the oval line. | |
lineformat.setOneColorGradient(Color.getGreen(), 1, GradientStyleType.HORIZONTAL, 1); | |
// Set the dash style of the oval. | |
lineformat.setDashStyle(MsoLineDashStyle.SOLID); | |
// Add another arc shape. | |
Oval oval2 = (com.aspose.cells.Oval) excelbook.getWorksheets().get(0).getShapes().addShape(MsoDrawingType.OVAL, | |
9, 2, 0, 0, 130, 130); | |
// Set the placement of the oval. | |
oval2.setPlacement(PlacementType.FREE_FLOATING); | |
// Set the line style. | |
LineFormat lineformat1 = oval2.getLine(); | |
lineformat.setDashStyle(MsoLineStyle.SINGLE); //setStyle(MsoLineStyle.SINGLE); | |
// Set the line weight. | |
lineformat1.setWeight(1); | |
// Set the color of the oval line. | |
lineformat1.setOneColorGradient(Color.getBlue(),1, GradientStyleType.HORIZONTAL, 1); | |
// Set the dash style of the oval. | |
lineformat1.setDashStyle(MsoLineDashStyle.SOLID); | |
// Save the excel file. | |
excelbook.save(dataDir + "AddinganOvalControl_out.xls"); |