Our solution provides a powerful platform independent API. Use our Mail merge document API to develop high-level software for C++ platform. This is a powerful software solution for merging templates in Word and PDF formats and data from custom data sources and further exporting the result to DOCX, PDF, HTML and other popular formats using C++.
Fast C++ library to execute Mail merge with Excel data.
Our Mail Merge SDK allows you to populate a Word template with your data from Excel sheet. Based on our Mail Merge API, you can create your own software solution using C++, which allows you to automate emails from Excel and generate reports with Excel data.
To Mail merge from Excel to Word, simply perform the Mail merge operation in C++ and export the result to any supported Word formats.
With our powerful Mail merge API, you can create personalized documents in C++ using just a Word Merge template and data from Excel.
How to use Mail merge from Excel:
With our high-fidelity Mail merge API, you can also perform a Mail merge operation with Google Docs. Just download the necessary data in Word and Excel format, make sure that the Word template contains merge fields and perform the Mail merge operation in C++, similar to the algorithm described in the previous section.
To try this powerful Mail merge web tool, load a Word template with special merge fields and data from Excel converted as described above. After running the code, export the result to any format using C++.
The following example shows how to perform a Mail merge operation to generate a Word document in C++:
dotnet add package Aspose.Words.Cpp
Copy
using namespace Aspose::Words;
using namespace Aspose::Cells;
auto doc = MakeObject<Document>(u"Input1.docx");
auto workbook = Factory::CreateIWorkbook(new String("Input2.xlsx"));
auto worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0);
auto dataRange = worksheet->GetICells()->GetMaxDisplayIRange();
auto dataTable = worksheet->GetICells()->ExportArray(
0, 0, dataRange->GetRowCount(), dataRange->GetColumnCount());
auto customersDataSource = MakeObject<BaseOperations::CustomerMailMergeDataSource>(dataTable);
doc->get_MailMerge()->Execute(customersDataSource);
doc->Save(u"Output.docx");
class ExcelDataSource : public IMailMergeDataSource
{
public:
System::String convertCellsString(String cellsValue)
{
auto valCh = cellsValue.charValue();
auto convertedString = System::String(valCh);
String::deleteCharValue(valCh);
return convertedString;
}
System::String get_TableName() override
{
return nullptr;
}
CustomerMailMergeDataSource(
intrusive_ptr<Aspose::Cells::Systems::Array2D<Aspose::Cells::Systems::Object*>> data)
{
dataIn = data;
for (int i = 0; i < data->At(0)->GetLength(); i++) {
auto fieldName = data->GetValue(0, i)->ToString();
m.insert({ convertCellsString(fieldName), i });
i++;
}
mRecordIndex = 0;
}
bool GetValue(System::String fieldName, SharedPtr<System::Object>& fieldValue) override
{
auto value = dataIn->GetValue(mRecordIndex, m.at(fieldName))->ToString();
if (value == new String(""))
return false;
fieldValue = System::ObjectExt::Box<System::String>(convertCellsString(value));
return true;
}
bool MoveNext() override
{
mRecordIndex++;
return mRecordIndex < dataIn->GetLength();
}
SharedPtr<IMailMergeDataSource> GetChildDataSource(System::String tableName) override
{
return nullptr;
}
intrusive_ptr<Aspose::Cells::Systems::Array2D<Aspose::Cells::Systems::Object*>> dataIn;
std::unordered_map<System::String, int> m;
int mRecordIndex;
};
There are three options to install Aspose.Words for C++ to your developer environment. Please choose one that resembles your needs and follow the step-by-step instructions:
You can use this C++ library to develop software on Microsoft Windows, Linux and macOS operating systems:
If you develop software for Linux or macOS, please check information on additional library dependencies (fontconfig and mesa-glu open-source packages) in Product Documentation.
You can perform Mail merge operation for other file formats: