OLE Nesnelerini Çalışma Kitabından Çıkarın

Bir Çalışma Kitabından OLE Nesnelerini Çıkarma

Şablon Çalışma Kitabı Oluşturma

  1. Microsoft Excel’de bir çalışma kitabı oluşturuldu.
  2. İ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
yapılacaklar:resim_alternatif_metin

Daha sonra OLE nesnelerini ayıklayın ve ilgili dosya türleriyle sabit diske kaydedin.

İndirin ve yükleyin Aspose.Cells

  1. İndir Aspose.Cells for .NET.
  2. 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.

  1. Referans Ekle
  2. 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();
}
}
}