إدارة الروابط الفائقة في ورقة العمل
العمل مع روابط فائقة
أنواع الروابط الفعلية
عموما، تدعم Aspose.Cells.GridWeb الروابط الفائقة التالية:
- روابط URL: روابط فائقة يمكن ربطها بعناوين URL على الويب.
- روابط النص: روابط URL تطبق على النص.
- روابط الصورة: روابط URL تطبق على الصور.
- روابط أوامر الخلية: روابط فائقة ترسل البيانات إلى خادم. تعمل مثل الزر الذي يشغل حدثاً في الخادم عند النقر.
توضح الأقسام أدناه استخدام جميع أنواع الروابط الفائقة بالتفصيل. كما تناقش كيفية الوصول إليها أو إزالتها.
إضافة الروابط المختصرة
روابط النص الفائقة
روابط URL الفائقة تبدو مشابهة إلى حد ما للروابط الفائقة البسيطة التي تراها عادةً على مواقع الويب. تعمل رابط URL الفائقة مثل مرساة في الخلية. كلما تم النقر عليها، تتنقل إلى صفحة ويب أو تفتح نافذة متصفح جديدة.
هناك أنواع مختلفة من روابط URL الفائقة:
- روابط نصية.
- روابط صور.
يمكن للمطورين تحديد صورة للرابط الفائق. إذا لم يتم تحديد صورة، يتم إنشاء رابط نصي؛ وإلا يتم إنشاء رابط صورة.
روابط النصوص
لإضافة رابط نصي إلى ورقة العمل:
- أضف عنصر تحكم Aspose.Cells.GridWeb إلى نموذج الويب الخاص بك.
- الوصول إلى ورقة العمل.
- إضافة ارتباط هايبرلينك إلى خلية في ورقة العمل.
- تعيين النص الذي سيظهر في الخلية.
- تعيين عنوان URL للارتباط.
- تعيين الهدف للارتباط الهايبرلينك، إذا كان ذلك مرغوبًا.
- تعيين تلميح الأداة إذا كان مرغوبًا.
المثال أدناه يضيف رابطين هايبرلينك إلى ورقة عمل. أحدهما ليس له هدف بينما الآخر معين إلى _parent.
الناتج: روابط نصية مضافة إلى ورقة العمل
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Accessing the reference of the worksheet that is currently active | |
GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex]; | |
// Adds a text hyperlink that goes to Aspose site and opens in new window | |
int linkIndex = sheet.Hyperlinks.Add("B1", "http://www.aspose.com"); | |
GridHyperlink link1 = sheet.Hyperlinks[linkIndex]; | |
link1.Target = "_blank"; | |
// Setting text and tool tip of the hyperlink | |
link1.TextToDisplay = "Aspose"; | |
link1.ScreenTip = "Open Aspose Web Site in new window"; | |
// Adding hyperlink to the worksheet to open in parent window | |
linkIndex = sheet.Hyperlinks.Add("B2", "http://www.aspose.com/docs/display/cellsnet/Aspose.Cells.GridWeb"); | |
GridHyperlink link2 = sheet.Hyperlinks[linkIndex]; | |
link2.Target = "_parent"; | |
// Setting text and tool tip of the hyperlink | |
link2.TextToDisplay = "Aspose.Grid Docs"; | |
link2.ScreenTip = "Open Aspose.Grid Docs in parent window"; |
روابط الصور
لإضافة رابط صورة:
- أضف عنصر تحكم Aspose.Cells.GridWeb إلى نموذج الويب الخاص بك.
- الوصول إلى ورقة العمل.
- إضافة رابط تشعبي إلى خلية.
- تعيين عنوان URL للصورة التي ستُعرض كارتباط.
- تعيين عنوان URL للارتباط.
- تعيين تلميح الأداة إذا كان مرغوبًا.
- تعيين نص الارتباط التشعبي، إذا كان مرغوبًا.
الإخراج: تمت إضافة روابط الصور إلى ورقة العمل
Setting the image hyperlink’s AltText fills a similar function as setting an
تعذر العثور على الصورة لعنوان URL للصورة
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Accessing the reference of the worksheet that is currently active | |
GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex]; | |
// Adding hyperlink to the worksheet | |
int linkIndex = sheet.Hyperlinks.Add("B5", "http://www.aspose.com"); | |
GridHyperlink link1 = sheet.Hyperlinks[linkIndex]; | |
link1.Target = "_blank"; | |
// Setting Image URL and tool tip of hyperlink | |
link1.ImageURL = "../Images/Aspose.Banner.gif"; | |
link1.ScreenTip = "Open Aspose Web Site in new window"; | |
// Adding hyperlink to the worksheet | |
linkIndex = sheet.Hyperlinks.Add("B6", "http://www.aspose.com/docs/display/cellsnet/Aspose.Cells.GridWeb"); | |
GridHyperlink link2 = sheet.Hyperlinks[linkIndex]; | |
link2.Target = "_blank"; | |
// Setting URL, tool tip and alt text of hyperlink | |
link2.ImageURL = "../Images/Aspose.Grid.gif"; | |
link2.ScreenTip = "Open Aspose.Grid Docs in new window"; | |
link2.AltText = "Open Aspose.Grid Docs in new window"; | |
// Resize the rows to display image nicely | |
sheet.Cells.SetRowHeight(4, 40); | |
sheet.Cells.SetRowHeight(5, 40); |
روابط الأوامر الخلية
روابط الخلية الخاصة بالأوامر الخلية هي نوع خاص من الروابط التشعبية التي تشغل حدث على الخادم بدلاً من فتح صفحة ويب. يمكن للمطورين إضافة رمز إلى الحدث على الخادم والقيام بأي مهمة عند النقر على الرابط التشعبي. تمكن هذه الميزة المطورين من إنشاء تطبيقات تفاعلية أكثر.
لإضافة رابط تشعبي للخلية:
- أضف عنصر تحكم Aspose.Cells.GridWeb إلى نموذج الويب الخاص بك.
- الوصول إلى ورقة العمل.
- إضافة رابط تشعبي إلى خلية.
- تعيين أمر الرابط التشعبي إلى أي قيمة مرغوبة. تستخدم القيمة من قبل معالج الأحداث رابط التشعبي للتعرف عليه.
- تعيين تلميح الأداة إذا كان مرغوبًا.
- تعيين عنوان URL للصورة التي سيتم عرضها كارتباط.
تمت إضافة رابط تشعبي إلى ورقة العمل
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Accessing the reference of the worksheet that is currently active | |
GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex]; | |
// Adding hyperlink to the worksheet | |
int linkIndex = sheet.Hyperlinks.Add("B8", ""); | |
GridHyperlink link1 = sheet.Hyperlinks[linkIndex]; | |
// Setting the cell command, tool tip and image URL for the hyperlink | |
link1.Command = "Click"; | |
link1.ScreenTip = "Click Here"; | |
link1.ImageURL = "../Images/button.jpg"; | |
// Resize the row to display image nicely | |
sheet.Cells.SetRowHeight(7, 30); |
معالجة الأحداث لروابط الأوامر الخلية
يحتاج المطورون إلى إنشاء معالج حدث لحدث CellCommand لعنصر التحكم GridWeb من أجل تنفيذ المهام المحددة عند النقر على رابط الأمر الخلية المحدد. يوفر معالج الحدث CellCommand نوع الخاصية CellEventArgs التي تقدم خاصية الوسيط. استخدم خاصية الوسيط لتعريف رابط تشعبي معين من خلال مقارنة قيمة أمره.
المثال أدناه ينشئ معالج حدث لرابط الأمر الخلية الذي تم إنشاؤه في الكود أعلاه. تم تعيين أمر CellCommand للرابط بالنقر. لذا، في معالج الحدث، قم بالتحقق منه أولاً ومن ثم أضف الكود الذي يعرض رسالة في الخلية A6.
يتم استدعاء معالج الأحداث عند النقر على الرابط التشعبي.
الإخراج: تمت إضافة نص إلى الخلية A6 عند النقر على الرابط التشعبي
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Event Handler for CellCommand event | |
protected void GridWeb1_CellCommand(object sender, Aspose.Cells.GridWeb.CellEventArgs e) | |
{ | |
// Checking the CellCommand of the hyperlink | |
if (e.Argument.Equals("Click")) | |
{ | |
// Accessing the reference of the worksheet that is currently active | |
GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex]; | |
// Adding value to "C8" cell | |
sheet.Cells["C8"].PutValue("Cell Command Hyperlink Clicked"); | |
// Resize the column to display message nicely | |
sheet.Cells.SetColumnWidth(2, 250); | |
} | |
} |
الوصول إلى الروابط التشعبية
للوصول إلى ارتباط تشعبي موجود:
- الوصول إلى الخلية التي تحتوي عليه.
- الحصول على مرجع الخلية.
- تمرير المرجع إلى طريقة الوصول إلى الارتباط التشعبي في مجموعة الارتباطات الخاصة للوصول إلى الارتباط التشعبي.
- تعديل خصائص الارتباط التشعبي.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Accessing the reference of the worksheet that is currently active | |
GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex]; | |
// Accessing a specific cell that contains hyperlink | |
GridCell cell = sheet.Cells["B1"]; | |
// Accessing the hyperlink from the specific cell | |
GridHyperlink link = sheet.Hyperlinks.GetHyperlink(cell); | |
if (link != null) | |
{ | |
// Modifying the text and URL of hyperlink | |
link.TextToDisplay = "Aspose.Blogs"; | |
link.Address = "http://www.aspose.com/Community/Blogs"; | |
} |
إزالة الروابط التشعبية
لإزالة ارتباط تشعبي:
- الوصول إلى ورقة العمل النشطة.
- إزالة ارتباط تشعبي باستخدام طريقة الإزالة في مجموعة الارتباطات الخاصة.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Accessing the reference of the worksheet that is currently active | |
GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex]; | |
// Removing hyperlink from the specific cell | |
sheet.Hyperlinks.Remove(new Data.GridCellArea() {StartRow = 0, EndRow = 0, StartColumn = 1, EndColumn = 1}); | |