در این مبحث نحوه ایجاد جدول در DOCX با استفاده از ++C را خواهیم دید. جداول معمولاً در اسناد word استفاده می شوند و می توانید با استفاده از C++ جدول را در DOCX وارد کنید. با استفاده از فراخوانی های ساده API می توانید جدول Word را در ++C وارد کنید.
مراحل افزودن جدول در DOCX با استفاده از C++
- آخرین نسخه Aspose.Words.Cpp را از NuGet نصب کنید
- شامل ارجاع به فضای نام Aspose::Words
- شیء Document Class را برای بارگیری DOCX برای اضافه کردن جدول ایجاد کنید
- برای مدیریت محتوای داخل DOCX، DocumentBuilder Class را نمونهسازی کنید
- از DocumentBuilder برای افزودن ردیف ها، سلول ها و تصویر در داخل سلول استفاده کنید
- با استفاده از روش Save، DOCX را با Table در 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++ را دیدیم. با این حال، در این مبحث یاد گرفتیم که چگونه با استفاده از C++ جدول را در DOCX وارد کنیم.