OLE Nesnelerini Çalışma Kitabından Çıkarın
Bazen bir çalışma kitabından OLE nesnelerini ayıklamanız gerekir. Aspose.Cells, bu Ole nesnelerinin çıkarılmasını ve kaydedilmesini destekler.
Bu makale, Visual Studio.Net’te bir konsol uygulamasının nasıl oluşturulacağını ve birkaç basit kod satırıyla bir çalışma kitabından farklı OLE nesnelerinin nasıl çıkarılacağını gösterir.
Bir Çalışma Kitabından OLE Nesnelerini Çıkarma
Şablon Çalışma Kitabı Oluşturma
- Microsoft Excel’de bir çalışma kitabı oluşturuldu.
- İlk çalışma sayfasına OLE nesneleri olarak bir Microsoft Word belgesi, bir Excel çalışma kitabı ve bir PDF belgesi ekleyin.
OLE nesneleri (OleFile.xls) içeren şablon belgesi |
---|
![]() |
Daha sonra OLE nesnelerini ayıklayın ve ilgili dosya türleriyle sabit diske kaydedin.
İndirin ve yükleyin Aspose.Cells
- İndir Aspose.Cells for .NET.
- Geliştirme bilgisayarınıza kurun.
Tüm Aspose bileşenleri kurulduğunda değerlendirme modunda çalışır. Değerlendirme modunun zaman sınırı yoktur ve yalnızca üretilen belgelere filigran ekler.
Proje Oluştur
BaşlamaVisual Studio.Net ve yeni bir konsol uygulaması oluşturun. Bu örnek, bir C# konsol uygulamasını gösterecektir, ancak VB.NET’i de kullanabilirsiniz.
- Referans Ekle
- Projenize Aspose.Cells bileşenine bir referans ekleyin, örneğin …\Program Files\Aspose\Aspose.Cells\Bin\Net1.0\Aspose.Cells.dll’ye bir referans ekleyin
OLE Nesnelerini Çıkarın
Aşağıdaki kod, OLE nesnelerini bulma ve ayıklama işini yapar. OLE nesneleri (DOC, XLS ve PDF dosyaları) diske kaydedilir.
// 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(); | |
} | |
} | |
} |