إدارة خصائص المستند

مقدمة

يوفر Microsoft Excel القدرة على إضافة خصائص إلى ملفات جداول البيانات. توفر هذه الخصائص المستندية معلومات مفيدة وتنقسم إلى فئتين كما هو موضح أدناه.

  • الخصائص المعرفة مسبقًا (المدمجة): الخصائص المدمجة تحتوي على معلومات عامة حول المستند مثل عنوان المستند واسم المؤلف وإحصائيات المستند وما إلى ذلك.
  • الخصائص المخصصة (المخصصة): الخصائص المخصصة المحددة من قبل المستخدم النهائي في شكل زوج اسم-قيمة.

كيفية إدارة خصائص المستند باستخدام Microsoft Excel

يسمح Microsoft Excel لك بإدارة خصائص المستندات لملفات Excel بطريقة WYSIWYG. يرجى اتباع الخطوات التالية لفتح مربع حوار الخصائص في Excel 2016.

  1. من القائمة ملف, حدد معلومات.
اختيار قائمة المعلومات
todo:image_alt_text
  1. انقر على عنوان الخصائص وحدد “الخصائص المتقدمة”.
النقر على اختيار الخصائص المتقدمة
todo:image_alt_text
  1. إدارة خصائص مستند الملف.
مربع الحوار الخصائص
todo:image_alt_text
في مربع حوار الخصائص، هناك علامات تبويب مختلفة، مثل العامة، والملخص، والإحصائيات، والمحتويات، والمخصصة. تساعد كل علامة تبويب في تكوين أنواع مختلفة من المعلومات ذات الصلة بالملف. تُستخدم علامة التبويب المخصصة لإدارة الخصائص المخصصة.

كيفية العمل مع خصائص المستند باستخدام Aspose.Cells

يمكن للمطورين إدارة خصائص الوثيقة بشكل ديناميكي باستخدام واجهات برمجة التطبيقات Aspose.Cells. تساعد هذه الميزة المطورين في تخزين معلومات مفيدة إلى جانب الملف، مثل متى تم استلام الملف ومعالجته وتسجيل الوقت وما إلى ذلك.

كيفية الوصول إلى خصائص المستند

تدعم واجهات برمجة التطبيقات Aspose.Cells كلا من أنواع خصائص المستند، المدمجة والمخصصة. يمثل Workbook لـ Aspose.Cells ملف Excel و، مثل ملف Excel، يمكن أن يحتوي Workbook الفصول المتعددة، يمثل كل منها بواسطة فئة Worksheet في حين أن مجموعة الفصول تمثل بواسطة فئة WorksheetCollection.

استخدم WorksheetCollection للوصول إلى خصائص المستند كما هو موضح أدناه.

كلا WorksheetCollection.BuiltInDocumentProperties و WorksheetCollection.CustomDocumentProperties يعيدان النسخة الفردية من Aspose.Cells.Properties.DocumentPropertyCollection. تحتوي هذه المجموعة على Aspose.Cells.Properties.DocumentProperty كائن ، كل منها يمثل خاصية مستند مدمجة أو مخصصة واحدة.

من متطلبات التطبيق كيفية الوصول إلى الخاصية ، أي؛ باستخدام فهرس أو اسم الخاصية من DocumentPropertyCollection كما هو موضح في المثال أدناه.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Instantiate a Workbook object
// Open an Excel file
Workbook workbook = new Workbook(dataDir + "sample-document-properties.xlsx");
// Retrieve a list of all custom document properties of the Excel file
Aspose.Cells.Properties.DocumentPropertyCollection customProperties = workbook.Worksheets.CustomDocumentProperties;
// Accessing a custom document property by using the property name
Aspose.Cells.Properties.DocumentProperty customProperty1 = customProperties["ContentTypeId"];
Console.WriteLine(customProperty1.Name + " " + customProperty1.Value);
// Accessing the same custom document property by using the property index
Aspose.Cells.Properties.DocumentProperty customProperty2 = customProperties[0];
Console.WriteLine(customProperty2.Name + " " + customProperty2.Value);

يتيح فئة Aspose.Cells.Properties.DocumentProperty استرداد اسم وقيمة ونوع خاصية المستند:

  • للحصول على اسم الخاصية ، استخدم DocumentProperty.Name.
  • للحصول على قيمة الخاصية ، استخدم DocumentProperty.Value. DocumentProperty.Value يعيد القيمة ككائن.
  • للحصول على نوع الخاصية ، استخدم DocumentProperty.Type. تعيد هذه واحدة من قيم تعداد PropertyType. بعد الحصول على نوع الخاصية ، استخدم واحدة من طرق DocumentProperty.ToXXX للحصول على قيمة النوع المناسب بدلاً من استخدام DocumentProperty.Value. تم وصف طرق DocumentProperty.ToXXX في الجدول أدناه.
اسم العضو الوصف طريقة ToXXX
Boolean نوع البيانات الخاصية هو بوليان ToBool
Date نوع البيانات الخاصية هو التاريخ والوقت. لاحظ أن Microsoft Excel يخزن فقط
الجزء التاريخي ، لا يمكن تخزين الوقت في خاصية مخصصة من هذا النوع
ToDateTime
Float نوع البيانات الخاصية هو Double ToDouble
Number نوع البيانات الخاصية هو Int32 ToInt
String نوع البيانات الخاصية هو String ToString
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Instantiate a Workbook object
// Open an Excel file
Workbook workbook = new Workbook(dataDir + "sample-document-properties.xlsx");
// Retrieve a list of all custom document properties of the Excel file
Aspose.Cells.Properties.DocumentPropertyCollection customProperties = workbook.Worksheets.CustomDocumentProperties;
// Accessing a custom document property
Aspose.Cells.Properties.DocumentProperty customProperty1 = customProperties[0];
// Storing the value of the document property as an object
object objectValue = customProperty1.Value;
// Accessing a custom document property
Aspose.Cells.Properties.DocumentProperty customProperty2 = customProperties[1];
// Checking the type of the document property and then storing the value of the
// document property according to that type
if (customProperty2.Type == Aspose.Cells.Properties.PropertyType.String)
{
string value = customProperty2.Value.ToString();
Console.WriteLine(customProperty2.Name + " : " + value);
}

كيفية إضافة أو إزالة خصائص المستند المخصصة

كما وصفنا في وقت سابق في بداية هذا الموضوع ، لا يمكن للمطورين إضافة أو إزالة الخصائص المدمجة لأن هذه الخصائص محددة من النظام ولكن من الممكن إضافة أو إزالة الخصائص المخصصة لأنها معرفة من قبل المستخدم.

كيفية إضافة الخصائص المخصصة

قدمت واجهات برمجة التطبيقات Aspose.Cells الطريقة Add لفئة CustomDocumentPropertyCollection من أجل إضافة خصائص مخصصة إلى المجموعة. تضيف طريقة Add الخاصية إلى ملف Excel وتعيد مرجعًا لخاصية المستند الجديدة ككائن Aspose.Cells.Properties.DocumentProperty.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Instantiate a Workbook object
// Open an Excel file
Workbook workbook = new Workbook(dataDir + "sample-document-properties.xlsx");
// Retrieve a list of all custom document properties of the Excel file
Aspose.Cells.Properties.CustomDocumentPropertyCollection customProperties = workbook.Worksheets.CustomDocumentProperties;
// Adding a custom document property to the Excel file
Aspose.Cells.Properties.DocumentProperty publisher = customProperties.Add("Publisher", "Aspose");
// Saving resultant spreadsheet
workbook.Save(dataDir + "out_sample-document-properties.xlsx");

كيفية تكوين خاصية مخصصة مرتبطة بالمحتوى

لإنشاء خاصية مخصصة مرتبطة بمحتوى نطاق محدد ، اتصل بالطريقة CustomDocumentPropertyCollection.AddLinkToContent وقم بتمرير اسم الخاصية والمصدر. يمكنك التحقق مما إذا كانت الخاصية مكونة كمرتبطة بالمحتوى باستخدام الخاصية DocumentProperty.IsLinkedToContent. علاوة على ذلك ، من الممكن أيضًا الحصول على نطاق المصدر باستخدام الخاصية Source من فئة DocumentProperty.

نحن نستخدم ملف نموذجي بسيط لبرنامج Microsoft Excel في المثال. يحتوي دفتر العمل على نطاق مسمى محدد يحمل التسمية MyRange والذي يشير إلى قيمة الخلية.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Instantiate an object of Workbook
// Open an Excel file
Workbook workbook = new Workbook(dataDir + "sample-document-properties.xlsx");
// Retrieve a list of all custom document properties of the Excel file
Aspose.Cells.Properties.CustomDocumentPropertyCollection customProperties = workbook.Worksheets.CustomDocumentProperties;
// Add link to content.
customProperties.AddLinkToContent("Owner", "MyRange");
// Accessing the custom document property by using the property name
Aspose.Cells.Properties.DocumentProperty customProperty1 = customProperties["Owner"];
// Check whether the property is lined to content
bool islinkedtocontent = customProperty1.IsLinkedToContent;
// Get the source for the property
string source = customProperty1.Source;
// Save the file
workbook.Save(dataDir + "out_sample-document-properties.xlsx");

كيفية إزالة الخصائص المخصصة

لإزالة الخصائص المخصصة باستخدام Aspose.Cells، قم بالاتصال بالطريقة DocumentPropertyCollection.Remove وقم بتمرير اسم خاصية المستند التي تريد إزالتها.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Instantiate a Workbook object
// Open an Excel file
Workbook workbook = new Workbook(dataDir + "sample-document-properties.xlsx");
// Retrieve a list of all custom document properties of the Excel file
Aspose.Cells.Properties.DocumentPropertyCollection customProperties = workbook.Worksheets.CustomDocumentProperties;
// Removing a custom document property
customProperties.Remove("Publisher");
// Save the file
workbook.Save(dataDir + "out_sample-document-properties.xlsx");

مواضيع متقدمة