Çalışma Kitabından OLE Nesneleri Çıkarma
Bazen, bir çalışma kitabından OLE nesnelerini çıkarmanız gerekebilir. Aspose.Cells for Python via .NET, bu Ole nesnelerini çıkarmayı ve kaydetmeyi destekler.
Bu makale, Visual Studio.Net’te bir konsol uygulaması oluşturmayı ve birkaç basit kod satırıyla bir çalışma kitabından farklı OLE nesnelerini nasıl çıkaracağınızı gösterir.
Bir Çalışma Kitabından OLE Nesneleri Çıkarma
Bir Şablon Çalışma Kitabı Oluşturma
- Microsoft Excel’de bir çalışma kitabı oluşturuldu.
- İlk çalışsayfasına Microsoft Word belgesi, bir Excel çalışma kitabı ve bir PDF belgesi olarak OLE nesneleri eklendi.
OLE nesneleri bulunan şablon belge (OleFile.xls) |
---|
![]() |
Ardından OLE nesneleri çıkarın ve bunları dosya türlerine göre sabit diske kaydedin.
Aspose.Cells for Python Excel Kütüphanesi Kullanarak OLE Nesnelerini Çıkarın
Aşağıdaki kod, OLE nesnelerini bulma ve çıkartma işlemini gerçekleştirir. (DOC, XLS ve PDF dosyaları) diskte kaydedilir.
from aspose.cells import FileFormatType, Workbook | |
from io import BytesIO | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Open the template file. | |
workbook = Workbook(dataDir + "oleFile.xlsx") | |
# Get the OleObject Collection in the first worksheet. | |
oles = workbook.worksheets[0].ole_objects | |
# Loop through all the oleobjects and extract each object in the worksheet. | |
for i in range(len(oles)): | |
ole = oles[i] | |
# Specify the output filename. | |
fileName = dataDir + "outOle" + str(i) + "." | |
# Specify each file format based on the oleobject format type. | |
if ole.file_format_type == FileFormatType.DOC: | |
fileName = "doc" | |
elif ole.file_format_type == FileFormatType.EXCEL_97_TO_2003: | |
fileName = "Xlsx" | |
elif ole.file_format_type == FileFormatType.PPT: | |
fileName = "Ppt" | |
elif ole.file_format_type == FileFormatType.PDF: | |
fileName = "Pdf" | |
elif ole.file_format_type == FileFormatType.UNKNOWN: | |
fileName = "Jpg" | |
# Save the oleobject as a new excel file if the object type is xls. | |
if ole.file_format_type == FileFormatType.XLSX: | |
ms = BytesIO() | |
if ole.object_data != None: | |
ms.write(ole.object_data) | |
oleBook = Workbook(ms) | |
oleBook.settings.is_hidden = False | |
oleBook.save(dataDir + "outOle" + str(i) + ".out.xlsx") | |
else: | |
if ole.object_data != None: | |
fs = open(fileName, "wb") | |
fs.write(ole.object_data) | |
fs.close() |