将WAV文件作为OLE对象插入
Contents
[
Hide
]
Aspose.Cells for Python via .NET 提供了将不同类型的 OLE 对象添加到工作表的功能。在以下示例中,我们将使用 Aspose.Cells for Python via .NET 提供的简单 API,将 wav 文件作为 OLE 对象添加。
This file contains hidden or 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") |