استخراج كائنات OLE من المصنف
Contents
[
Hide
]
في بعض الأحيان ، تحتاج إلى استخراج كائنات OLE من مصنف. يدعم Aspose.Cells استخراج وحفظ عناصر Ole هذه.
يوضح هذا المقال كيفية إنشاء تطبيق وحدة تحكم في Visual Studio.Net واستخراج كائنات OLE مختلفة من مصنف باستخدام بضعة أسطر بسيطة من التعليمات البرمجية.
استخراج كائنات OLE من مصنف
إنشاء قالب مصنف
- إنشاء مصنف في Microsoft Excel.
- قم بإضافة مستند Word Microsoft ومصنف Excel ومستند PDF ككائنات OLE في ورقة العمل الأولى.
مستند قالب به كائنات OLE (OleFile.xls) |
---|
![]() |
قم بعد ذلك باستخراج كائنات OLE وحفظها على القرص الثابت مع أنواع الملفات الخاصة بها.
قم بتنزيل وتثبيت Aspose.Cells
- تحميل Aspose.Cells for .NET.
- قم بتثبيته على جهاز الكمبيوتر الخاص بك.
جميع مكونات Aspose ، عند تثبيتها ، تعمل في وضع التقييم. لا يوجد حد زمني لوضع التقييم ويقوم فقط بحقن العلامات المائية في المستندات المنتجة.
أنشئ مشروعًا
بدايةمرئي Studio.Net وإنشاء تطبيق وحدة تحكم جديد. سيعرض هذا المثال تطبيق وحدة تحكم C# ، ولكن يمكنك استخدام VB.NET أيضًا.
- أضف المراجع
- أضف مرجعًا إلى مكون Aspose.Cells إلى مشروعك ، على سبيل المثال أضف مرجعًا إلى … \ Program Files \ Aspose \ Aspose.Cells \ Bin \ Net1.0 \ Aspose.Cells.dll
استخراج كائنات OLE
يقوم الكود أدناه بالعمل الفعلي لإيجاد واستخراج كائنات OLE. يتم حفظ كائنات OLE (ملفات DOC و XLS و PDF) على القرص.
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-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open the template file. | |
Workbook workbook = new Workbook(dataDir + "oleFile.xlsx"); | |
// Get the OleObject Collection in the first worksheet. | |
Aspose.Cells.Drawing.OleObjectCollection oles = workbook.Worksheets[0].OleObjects; | |
// Loop through all the oleobjects and extract each object in the worksheet. | |
for (int i = 0; i < oles.Count; i++) | |
{ | |
Aspose.Cells.Drawing.OleObject ole = oles[i]; | |
// Specify the output filename. | |
string fileName = dataDir+ "outOle" + i + "."; | |
// Specify each file format based on the oleobject format type. | |
switch (ole.FileFormatType) | |
{ | |
case FileFormatType.Doc: | |
fileName += "doc"; | |
break; | |
case FileFormatType.Excel97To2003: | |
fileName += "Xlsx"; | |
break; | |
case FileFormatType.Ppt: | |
fileName += "Ppt"; | |
break; | |
case FileFormatType.Pdf: | |
fileName += "Pdf"; | |
break; | |
case FileFormatType.Unknown: | |
fileName += "Jpg"; | |
break; | |
default: | |
//........ | |
break; | |
} | |
// Save the oleobject as a new excel file if the object type is xls. | |
if (ole.FileFormatType == FileFormatType.Xlsx) | |
{ | |
MemoryStream ms = new MemoryStream(); | |
if (ole.ObjectData != null) | |
{ | |
ms.Write(ole.ObjectData, 0, ole.ObjectData.Length); | |
Workbook oleBook = new Workbook(ms); | |
oleBook.Settings.IsHidden = false; | |
oleBook.Save(dataDir + "outOle" + i + ".out.xlsx"); | |
} | |
} | |
// Create the files based on the oleobject format types. | |
else | |
{ | |
if (ole.ObjectData != null) | |
{ | |
FileStream fs = File.Create(fileName); | |
fs.Write(ole.ObjectData, 0, ole.ObjectData.Length); | |
fs.Close(); | |
} | |
} | |
} |