Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
OLE (Object Linking and Embedding) is a framework for compound‑document technology. Briefly, a compound document is something like a desktop that can contain visual and informational objects of all kinds: text, calendars, animations, sound, motion video, 3D, continually updated news, controls, and so forth. Each desktop object is an independent program entity that can interact with a user and also communicate with other objects on the desktop.
OLE is supported by many different programs and is used to make content created in one program available in another. For example, you can insert a Microsoft Word document into Microsoft Excel. To see what types of content you can insert, click Object on the Insert menu. Only programs that are installed on the computer and that support OLE objects appear in the Object type box.
Aspose.Cells for Node.js via C++ supports adding, extracting, and manipulating OLE objects in worksheets. For this reason, Aspose.Cells has the OleObjectCollection class, used to add a new OLE object to the collection. Another class, OleObject, represents an OLE object. It has some important members:
The following example shows how to add OLE objects into a worksheet.
const fs = require("fs");
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
// Instantiate a new Workbook.
const workbook = new AsposeCells.Workbook();
// Get the first worksheet.
const sheet = workbook.getWorksheets().get(0);
// Define a string variable to store the image path.
const imageUrl = path.join(dataDir, "logo.jpg");
// Get the picture into a stream.
const imageData = fs.readFileSync(imageUrl);
// Get an Excel file path in a variable.
const filePath = path.join(dataDir, "book1.xls");
// Get the file into a stream.
const objectData = fs.readFileSync(filePath);
// Add an OLE object into the worksheet with the image
// shown in MS Excel.
sheet.getOleObjects().add(14, 3, 200, 220, imageData);
// Set embedded OLE object data.
sheet.getOleObjects().get(0).setObjectData(objectData);
// Save the Excel file
workbook.save(path.join(dataDir, "output.out.xls"));
The following example shows how to extract OLE objects from a workbook. The example gets different OLE objects from an existing XLS file and saves separate files (DOC, XLSX, PPT, PDF, etc.) based on each OLE object’s file‑format type.
After running the code, we can save different files based on their respective OLE object format types.
const fs = require("fs");
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
// Open the template file.
const workbook = new AsposeCells.Workbook(path.join(dataDir, "book1.xls"));
// Get the OleObject collection in the first worksheet.
const oles = workbook.getWorksheets().get(0).getOleObjects();
// Loop through all the oleobjects and extract each object.
for (let i = 0; i < oles.getCount(); i++) {
const ole = oles.get(i);
// Specify the output filename.
let fileName = path.join(dataDir, `ole_${i}.`);
// Specify each file format based on the OLE object format type.
switch (ole.getFileFormatType()) {
case AsposeCells.FileFormatType.Doc:
fileName += "doc";
break;
case AsposeCells.FileFormatType.Xlsx:
fileName += "xlsx";
break;
case AsposeCells.FileFormatType.Ppt:
fileName += "ppt";
break;
case AsposeCells.FileFormatType.Pdf:
fileName += "pdf";
break;
case AsposeCells.FileFormatType.Unknown:
fileName += "jpg";
break;
default:
//........
break;
}
// Save the OLE object as a new Excel file if the object type is Xlsx.
if (ole.getFileFormatType() === AsposeCells.FileFormatType.Xlsx) {
const ms = new Uint8Array(ole.getObjectData());
const oleBook = new AsposeCells.Workbook(ms);
oleBook.getSettings().setIsHidden(false);
oleBook.save(path.join(dataDir, `Excel_File${i}.out.xlsx`));
}
// Create the files based on the OLE object format types.
else {
fs.writeFileSync(fileName, ole.getObjectData());
}
}
Aspose.Cells for Node.js via C++ supports extracting objects of uncommon types like MOL (a molecular‑data file containing information about atoms and bonds). The following code snippet demonstrates extracting an embedded MOL file and saving it to disk by using this sample Excel file.
const path = require("path");
const fs = require("fs");
const AsposeCells = require("aspose.cells.node");
// Directories
const sourceDir = path.join(__dirname, "data");
const outputDir = path.join(__dirname, "output");
const filePath = path.join(sourceDir, "EmbeddedMolSample.xlsx");
const workbook = new AsposeCells.Workbook(filePath);
let index = 1;
const worksheets = workbook.getWorksheets();
const sheetCount = worksheets.getCount();
for (let i = 0; i < sheetCount; i++) {
const sheet = worksheets.get(i);
const oles = sheet.getOleObjects();
const oleCount = oles.getCount();
for (let j = 0; j < oleCount; j++) {
const ole = oles.get(j);
const fileName = path.join(outputDir, `OleObject${index}.mol`);
const fileStream = fs.createWriteStream(fileName);
fileStream.write(Buffer.from(ole.getObjectData()));
fileStream.end();
index++;
}
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.