Çalışma Kitabından OLE Nesneleri Çıkarma
Contents
[
Hide
]
Bazen, bir çalışma kitabından Ole nesnelerini çıkartmanız gerekebilir. Aspose.Cells, bu Ole nesnelerini çıkartmayı ve kaydetmeyi destekler ve bu makalede gösterildiği gibi bunu yapabilir.
Bir Çalışma Kitabından OLE Nesneleri Çıkarma
Bir Şablon Çalışma Kitabı Oluşturma
- İlk çalışma sayfasına bir Microsoft Word belgesi, bir Excel çalışma kitabı ve bir PDF belgesi olarak Ole nesneleri eklendi.
- İlk çalışma sayfasına bir Microsoft Word belgesi, bir Excel çalışma kitabı ve bir OLE nesnesi olarak PDF belgesi ekleyin.
OLE Nesnelerini Çıkarın
Aşağıdaki kod, DOCX, XLSX, PPTX ve PDF dosyaları olarak gömülü nesneleri bulma ve çıkarma işlemini gerçekleştirir.
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ExtractOLEObjects.class); | |
// Instantiating a Workbook object, Open the template file. | |
Workbook workbook = new Workbook(dataDir + "oleFile.xlsx"); | |
// Get the OleObject Collection in the first worksheet. | |
OleObjectCollection objects = workbook.getWorksheets().get(0).getOleObjects(); | |
// Loop through all the OleObjects and extract each object in the worksheet. | |
for (int i = 0; i < objects.getCount(); i++) { | |
OleObject object = objects.get(i); | |
// Specify the output filename. | |
String fileName = "D:/object" + i + "."; | |
// Specify each file format based on the OleObject format type. | |
switch (object.getFileFormatType()) { | |
case FileFormatType.DOCX: | |
fileName += "docx"; | |
break; | |
case FileFormatType.XLSX: | |
fileName += "xlsx"; | |
break; | |
case FileFormatType.PPTX: | |
fileName += "pptx"; | |
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 (object.getFileFormatType() == FileFormatType.XLSX) { | |
byte[] bytes = object.getObjectData(); | |
InputStream is = new ByteArrayInputStream(bytes); | |
Workbook oleBook = new Workbook(is); | |
oleBook.getSettings().setHidden(false); | |
oleBook.save(fileName); | |
} | |
// Create the files based on the OleObject format types. | |
else { | |
FileOutputStream fos = new FileOutputStream(fileName); | |
fos.write(object.getObjectData()); | |
fos.close(); | |
} | |
} |
Sonuç:
Bu makale, Aspose.Cells kullanarak bir çalışma kitabından OLE nesnelerini çıkarmayı göstermektedir. Umuyoruz ki, kendi senaryolarınızda bu seçenekleri kullanmanıza olanak tanıyan bazı bilgiler sunacaktır.