Web Extensions - Office Add-ins with C++
Web Extensions extend Office applications and interact with the content in Office documents. Web Extensions add additional functionality to Office clients to improve the user experience and productivity.
Aspose.Cells also provides the ability to work with Web Extensions.
Add Web Extension
You may add Web Extensions (Office Add-ins) in Excel by clicking the Insert tab and then clicking the Store/Get Add-ins link. In the Add-ins box, browse for the add-in you want and add it.
Aspose.Cells also provides the feature to add Web Extensions by using the WebExtension and WebExtensionTaskPane classes. The following code sample demonstrates the use of WebExtension and WebExtensionTaskPane classes to add a web extension to an Excel file. Please see the output Excel file generated by the code for reference.
Sample Code
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Output directory path
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Create a new workbook
Workbook workbook;
// Get the WebExtension collection from the workbook's worksheets
WebExtensionCollection extensions = workbook.GetWorksheets().GetWebExtensions();
WebExtensionTaskPaneCollection taskPanes = workbook.GetWorksheets().GetWebExtensionTaskPanes();
// Add a new WebExtension and WebExtensionTaskPane
int32_t extensionIndex = extensions.Add();
int32_t taskPaneIndex = taskPanes.Add();
// Get the newly added WebExtension and configure it
WebExtension extension = extensions.Get(extensionIndex);
extension.GetReference().SetId(u"wa104379955");
extension.GetReference().SetStoreName(u"en-US");
extension.GetReference().SetStoreType(WebExtensionStoreType::OMEX);
// Get the newly added WebExtensionTaskPane and configure it
WebExtensionTaskPane taskPane = taskPanes.Get(taskPaneIndex);
taskPane.SetIsVisible(true);
taskPane.SetDockState(u"right");
taskPane.SetWebExtension(extension);
// Save the workbook with the added WebExtension
workbook.Save(outDir + u"AddWebExtension_Out.xlsx");
std::cout << "WebExtension added successfully!" << std::endl;
Aspose::Cells::Cleanup();
}
Access Web Extension Information
Aspose.Cells provides the ability to access the information of Web Extensions in an Excel file. The following code sample demonstrates how to access web extension information by loading the sample Excel file. Please see the console output generated by the code for reference.
Sample Code
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Load sample Excel file
Workbook workbook(srcDir + u"WebExtensionsSample.xlsx");
// Get the collection of web extension task panes
WebExtensionTaskPaneCollection taskPanes = workbook.GetWorksheets().GetWebExtensionTaskPanes();
// Iterate through each task pane and print its properties
for (int i = 0; i < taskPanes.GetCount(); ++i)
{
WebExtensionTaskPane taskPane = taskPanes.Get(i);
std::cout << "Width: " << taskPane.GetWidth() << std::endl;
std::cout << "IsVisible: " << taskPane.IsVisible() << std::endl;
std::cout << "IsLocked: " << taskPane.IsLocked() << std::endl;
std::cout << "DockState: " << taskPane.GetDockState().ToUtf8() << std::endl;
std::cout << "StoreName: " << taskPane.GetWebExtension().GetReference().GetStoreName().ToUtf8() << std::endl;
std::cout << "WebExtension.Id: " << taskPane.GetWebExtension().GetId().ToUtf8() << std::endl;
}
Aspose::Cells::Cleanup();
return 0;
}
Console Output
Width: 350
IsVisible: True
IsLocked: False
DockState: right
StoreName: en-US
StoreType: OMEX
WebExtension.Id: 95D7ECE8-1355-492B-B6BF-27D25D0B0EEF