Come creare tabelle in DOCX usando C++

In questo argomento vedremo come creare una tabella in DOCX usando C++. Le tabelle sono comunemente usate all’interno di documenti Word e puoi inserire tabelle in DOCX usando C++. Puoi inserire la tabella di Word in C++ usando semplici chiamate API.

Passaggi per aggiungere una tabella in DOCX usando C++

  1. Installa l’ultima versione di Aspose.Words.Cpp da NuGet
  2. Includi il riferimento allo spazio dei nomi Aspose::Words
  3. Crea Document Class oggetto per caricare DOCX per l’aggiunta di una tabella
  4. Crea un’istanza di DocumentBuilder Class per gestire il contenuto all’interno di DOCX
  5. Usa DocumentBuilder per aggiungere righe, celle e immagini all’interno della cella
  6. Salva il DOCX con la tabella in C++ usando il metodo Save

Nell’esempio seguente, puoi creare una tabella di Word utilizzando C++ senza dipendere da Microsoft Word. Puoi formattare il contenuto all’interno delle celle della tabella e abbiamo mostrato come aggiungere anche l’immagine all’interno della cella.

Codice per aggiungere una tabella in DOCX usando 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");
}
};

In precedenza, abbiamo visto Come aggiungere immagini in DOCX usando C++. Tuttavia, in questo argomento abbiamo imparato come inserire una tabella in DOCX usando C++.

 Italiano