Tabel maken in DOCX met C++

In dit onderwerp zullen we zien hoe u een tabel kunt maken in DOCX met behulp van C++. Tabellen worden vaak gebruikt in Word-documenten en u kunt een tabel in DOCX invoegen met C++. U kunt een Word-tabel in C++ invoegen met behulp van eenvoudige API-aanroepen.

Stappen om een tabel in DOCX toe te voegen met C++

  1. Installeer de nieuwste versie van Aspose.Words.Cpp van NuGet
  2. Verwijzing naar Aspose::Words naamruimte opnemen
  3. Maak een Document Class object om DOCX te laden voor het toevoegen van een tabel
  4. Instantieer DocumentBuilder Class om de inhoud in DOCX te beheren
  5. Gebruik DocumentBuilder om rijen, cellen en afbeeldingen in de cel toe te voegen
  6. Sla de DOCX op met tabel in C++ met behulp van de Save-methode

In het onderstaande voorbeeld kunt u een Word-tabel maken met C++ zonder afhankelijkheid van Microsoft Word. U kunt de inhoud in tabelcellen opmaken en we hebben laten zien hoe u ook een afbeelding in de cel kunt toevoegen.

Code om tabel in DOCX toe te voegen met C++

#pragma once
#include <cstdint>
#include <iostream>
#include <Aspose.Words.Cpp/Document.h>
#include <Aspose.Words.Cpp/DocumentBase.h>
#include <Aspose.Words.Cpp/DocumentBuilder.h>
#include <Aspose.Words.Cpp/Drawing/Shape.h>
#include <Aspose.Words.Cpp/HeaderFooterType.h>
#include <Aspose.Words.Cpp/Saving/SaveOutputParameters.h>
#include <system/array.h>
#include <system/exceptions.h>
#include <Aspose.Words.Cpp/License.h>
#include <system/io/path.h>
using System::ArrayPtr;
using System::MakeArray;
using System::MakeObject;
using System::SharedPtr;
using System::String;
using namespace Aspose::Words;
class CreateTableInWordDocumentUsingCpp
{
public:
void AddTableinWordDocument()
{
// Set License file name
System::String LicenseFile = u"Aspose.Total.NET.lic";
// Setting the Aspose.Words before creating Word document
SharedPtr<License> wordsLicenseForTable = System::MakeObject<License>();
// Setting product license
wordsLicenseForTable->SetLicense(LicenseFile);
// Instantiate Document class to load DOCX and add table
SharedPtr<Document> AddTableToWordDOC = MakeObject<Document>(u"WordDocument.docx");
// Instantiate DocumentBuilder class to manage document content
SharedPtr<DocumentBuilder> TableWriter = MakeObject<DocumentBuilder>(AddTableToWordDOC);
// Mark the start of table
TableWriter->StartTable();
// Insert Row and first Cell inside Word Table
TableWriter->InsertCell();
// Add some text in Table Cell
TableWriter->Write(u"Table Row 1 and Cell 1");
// Add a new Cell inside Row
TableWriter->InsertCell();
// Insert an Image in Word Table Cell
TableWriter->InsertImage(u"image in table.jpg");
// Mark end of Table Row
TableWriter->EndRow();
// Mark end of Word Table creation
TableWriter->EndTable();
// Save the word document with table to docx format
AddTableToWordDOC->Save(u"InsertTableinDocx.docx");
}
};

Eerder zagen we Hoe een afbeelding in DOCX toe te voegen met C++. In dit onderwerp hebben we echter geleerd hoe we een tabel in DOCX kunnen invoegen met C++.

 Nederlands