Ebben a témakörben látni fogjuk, hogyan hozhat létre táblázatot a DOCX nyelven C++ használatával. A táblákat általában Word dokumentumokon belül használják, és a DOCX-ben táblázatot szúrhat be a C++ használatával. A Word táblázatot beszúrhatja a C++ nyelven egyszerű API-hívásokkal.
A táblázat hozzáadásának lépései a DOCX-ben C++ használatával
- Telepítse a Aspose.Words.Cpp legújabb verzióját a NuGetből
- Tartalmazzon hivatkozást a Aspose::Words névtérre
- Hozzon létre Document Class objektumot a DOCX betöltéséhez a táblázat hozzáadásához
- Példányosítása DocumentBuilder Class a DOCX-en belüli tartalom kezeléséhez
- A DocumentBuilder segítségével sorokat, cellákat és képeket adhat a cellán belülre
- Mentse el a DOCX-et táblázattal C++ nyelven a Mentés módszerrel
Az alábbi példában Word-táblázatot hozhat létre C++ használatával anélkül, hogy a Microsoft Word-től függne. A táblázat celláiban formázhatja a tartalmat, és megmutattuk, hogyan lehet képet hozzáadni a cellákhoz.
Kód táblázat hozzáadásához DOCX-ben C++ használatával
#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"); | |
} | |
}; |
Korábban láttuk a következőt: Kép hozzáadása DOCX-ben C++ használatával. Ebben a témában azonban megtanultuk, hogyan lehet táblázatot beszúrni DOCX-be C++ használatával.