Inserting a WAV file as an Ole Object
Contents
[
Hide
]
Aspose.Cells for Python via .NET provides the functionality to add different types of OLE objects to the excel worksheets. We will see in the following code examples, how to add a wav file as an OLE object using simple APIs provided by Aspose.Cells for Python via .NET.
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
from aspose.cells import FileFormatType, Workbook | |
import bytearray | |
# 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(".") | |
# Define a string variable to store the image path. | |
ImageUrl = dataDir + "image2.jpg" | |
# Get the picture into the streams. | |
fs = open(ImageUrl, "rb") | |
# Define a byte array. | |
imageData = bytearray(utils.filesize(fs)) | |
# Obtain the picture into the array of bytes from streams. | |
fs.readinto(imageData) | |
# Close the stream. | |
fs.close() | |
# Get an excel file path in a variable. | |
path = dataDir + "chord.wav" | |
# Get the file into the streams. | |
fs = open(path, "rb") | |
# Define an array of bytes. | |
objectData = bytearray(utils.filesize(fs)) | |
# Store the file from streams. | |
fs.readinto(objectData) | |
# Close the stream. | |
fs.close() | |
intIndex = 0 | |
# Instantiate a new Workbook. | |
workbook = Workbook() | |
sheet = workbook.worksheets[0] | |
# Add Ole Object | |
sheet.ole_objects.add(14, 3, 200, 220, imageData) | |
workbook.worksheets[0].ole_objects[intIndex].file_format_type = FileFormatType.UNKNOWN | |
workbook.worksheets[0].ole_objects[intIndex].object_data = objectData | |
workbook.worksheets[0].ole_objects[intIndex].object_source_full_name = path | |
# Save the excel file | |
workbook.save(dataDir + "testWAV.out.xlsx") |