在Node.js和C++中插入WAV文件作为Ole对象
Contents
[
Hide
]
Aspose.Cells提供功能,允许在Excel工作表中添加各种类型的OLE对象。我们将在以下代码示例中看到如何使用Aspose.Cells提供的简单API将WAV文件添加为OLE对象。
const fs = require("fs");
const AsposeCells = require("aspose.cells.node");
const path = require("path");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
// Define a string variable to store the image path.
const imageUrl = path.join(dataDir, "image2.jpg");
imageData = fs.readFileSync(imageUrl);
// Get an excel file path in a variable.
const filePath = path.join(dataDir, "chord.wav");
fs.writeFileSync(filePath, Buffer.from('RIFF____WAVEfmt \x10\x00\x00\x00\x01\x00\x01\x00\x00\x04\x00\x00\x00\x04\x00\x00\x01\x00\x08\x00data____', 'binary'));
// Get the file into the streams.
const objectData = fs.readFileSync(filePath);
const intIndex = 0;
// Instantiate a new Workbook.
const workbook = new AsposeCells.Workbook();
const sheet = workbook.getWorksheets().get(0);
// Add Ole Object
sheet.getOleObjects().add(14, 3, 200, 220, imageData);
workbook.getWorksheets().get(0).getOleObjects().get(intIndex).setFileFormatType(AsposeCells.FileFormatType.Unknown);
workbook.getWorksheets().get(0).getOleObjects().get(intIndex).setObjectData(objectData);
workbook.getWorksheets().get(0).getOleObjects().get(intIndex).setObjectSourceFullName(filePath);
// Save the excel file
workbook.save(path.join(dataDir, "testWAV.out.xlsx"));