في هذا الموضوع ، سنرى كيفية إنشاء جدول في DOCX باستخدام C ++. تُستخدم الجداول بشكل شائع داخل مستندات الكلمات ويمكنك إدراج جدول في DOCX باستخدام C ++. يمكنك إدراج جدول Word في C ++ باستخدام مكالمات API بسيطة.
خطوات إضافة جدول في DOCX باستخدام C ++
- قم بتثبيت أحدث إصدار من Aspose.Words.Cpp من NuGet
- قم بتضمين مرجع إلى مساحة الاسم Aspose::Words
- قم بإنشاء كائن Document Class لتحميل DOCX لإضافة الجدول
- إنشاء مثيل DocumentBuilder Class لإدارة المحتوى داخل DOCX
- استخدم DocumentBuilder لإضافة صفوف وخلايا وصورة داخل الخلية
- احفظ DOCX مع جدول في C ++ باستخدام طريقة الحفظ
في المثال أدناه ، يمكنك إنشاء جدول Word باستخدام C ++ دون الاعتماد على Microsoft Word. يمكنك تنسيق المحتوى داخل خلايا الجدول وقد أظهرنا كيفية إضافة صورة داخل الخلية أيضًا.
كود لإضافة جدول في DOCX باستخدام 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"); | |
} | |
}; |
في السابق ، رأينا كيفية إضافة صورة في DOCX باستخدام C ++. ومع ذلك ، في هذا الموضوع تعلمنا كيفية إدراج الجدول في DOCX باستخدام C ++.