Infoga OLE-objekt i arbetsbladet
Contents
[
Hide
]
Möjliga användningsscenarier
Aspose.Cells låter dig infoga ett OLE-objekt i kalkylbladet. Snälla användIWorksheet->GetIOleObjects()->Add()metod för detta ändamål. Du behöver en bildbyte-array som kommer att användas för att infoga OLE-objektet i kalkylbladet och Ole-objektdatabytes som kommer att vara ditt faktiska objekt. för att infoga Ole-objektet i kalkylbladet.
Infoga OLE-objekt i arbetsbladet
Följande exempelkod skapar arbetsboksobjektet och infogar Ole-objektet i det första kalkylbladet och sparar det somutdata Excel-fil . Vänligen seAspose Logotyp används som bildbyte ochmata in Excel-fil används som Ole-objektdata inuti koden för referens.
Exempelkod
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
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C | |
// Source directory path. | |
StringPtr srcDir = new String("..\\Data\\01_SourceDirectory\\"); | |
// Output directory path. | |
StringPtr outDir = new String("..\\Data\\02_OutputDirectory\\"); | |
// Path of output Excel file. | |
StringPtr outputInsertingOLEObjectsIntoWorksheet = outDir->StringAppend(new String("outputInsertingOLEObjectsIntoWorksheet.xlsx")); | |
// Instantiate a new workbook. | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(); | |
// Get the first worksheet. | |
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0); | |
//Create File object. | |
intrusive_ptr<Aspose::Cells::Systems::IO::File> ioFile = new Aspose::Cells::Systems::IO::File(); | |
// Read Image for Ole Object into array of bytes. | |
StringPtr imagePath = srcDir->StringAppend(new String("AsposeLogo.png")); | |
intrusive_ptr<Array1D<Byte>> imageData = ioFile->ReadAllBytes(imagePath); | |
// Read Ole Object into array of bytes. | |
StringPtr oleObjectPath = srcDir->StringAppend(new String("inputInsertOleObject.xlsx")); | |
intrusive_ptr<Array1D<Byte>> oleObjectData = ioFile->ReadAllBytes(oleObjectPath); | |
// Add an Ole object into the worksheet with the image. | |
Aspose::Cells::Systems::Int32 idx = worksheet->GetIOleObjects()->Add(2, 2, 200, 220, imageData); | |
// Set the Ole object data. | |
intrusive_ptr<Aspose::Cells::Drawing::IOleObject> oleObj = worksheet->GetIOleObjects()->GetObjectByIndex(idx); | |
oleObj->SetObjectData(oleObjectData); | |
// Save the workbook. | |
workbook->Save(outputInsertingOLEObjectsIntoWorksheet); |