C++ pangembang bisa gampang nggawe Word mung nggunakake API produk sing kuat. Tegese solusi kita bakal nyedhiyakake programer kabeh sing dibutuhake kanggo nggawe Word ing C++.
Kanthi pangembang perpustakaan C++ kita bisa nggawe Word saka awal. Kanggo nindakake iki, pangembang C++ mung kudu nindakake sawetara langkah:
Wigati dicathet yen dokumen kosong sacara teknis mesthine ngemot siji paragraf, dadi nalika sampeyan nggawe Word dokumen kanthi program, sampeyan bakal entuk struktur dokumen dhasar kasebut.
Elinga yen sampeyan bisa langsung nambah konten menyang Word file sing mentas digawe. Mangkono, sampeyan bakal entuk ora mung dokumen kosong, nanging dokumen sing ngemot konten sing dibutuhake. Kanggo informasi luwih lengkap babagan cara ngowahi dokumen, deleng kaca Editing.
Pustaka C++ iki ngidini sampeyan nggawe Word dokumen kanthi program. Coba fungsi sing kuat lan deleng carane nggawe Word ing sawetara format nggunakake conto ing ngisor iki:
dotnet add package Aspose.Words.Cpp
Nyalin
using namespace Aspose::Words;
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto font = builder->get_Font();
font->set_Name(u"Courier New");
font->set_Color(System::Drawing::Color::get_Blue());
font->set_Size(36);
font->set_HighlightColor(System::Drawing::Color::get_Yellow());
builder->Write(u"Morbi enim nunc faucibus a.");
doc->Save(u"Output.docx");
using namespace Aspose::Words;
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto firstRun = MakeObject<Run>(doc, u"Proin eros metus, sagittis sed. ");
auto secondRun = MakeObject<Run>(doc, u"Morbi enim nunc faucibus a.");
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(firstRun);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(secondRun);
builder->MoveTo(secondRun);
builder->StartBookmark(u"Aspose bookmark");
// Yen NextSibling null, banjur paling kamungkinan iki Run pungkasan ing Paragraf.
if (secondRun->get_NextSibling() != NULL)
builder->MoveTo(secondRun->get_NextSibling());
else
builder->MoveTo(secondRun->get_ParentParagraph());
builder->EndBookmark(u"Aspose bookmark");
doc->Save(u"Output.docx");
using namespace Aspose::Words;
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto firstRun = MakeObject<Run>(doc, u"Proin eros metus, sagittis sed. ");
auto secondRun = MakeObject<Run>(doc, u"Morbi enim nunc faucibus a.");
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(firstRun);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(secondRun);
builder->MoveTo(secondRun);
builder->StartBookmark(u"Aspose bookmark");
// Yen NextSibling null, banjur paling kamungkinan iki Run pungkasan ing Paragraf.
if (secondRun->get_NextSibling() != NULL)
builder->MoveTo(secondRun->get_NextSibling());
else
builder->MoveTo(secondRun->get_ParentParagraph());
builder->EndBookmark(u"Aspose bookmark");
auto saveOptions = MakeObject<PdfSaveOptions>();
saveOptions->get_OutlineOptions()->get_BookmarksOutlineLevels()->Add(u"Aspose bookmark", 1);
doc->Save(u"Output.docx", saveOptions);
using namespace Aspose::Words;
auto doc = MakeObject<Document>();
auto run = MakeObject<Run>(doc, u"Proin eros metus, sagittis sed.");
auto para = doc->get_FirstSection()->get_Body()->get_FirstParagraph();
para->AppendChild(run);
auto comment = MakeObject<Comment>(doc, u"John Doe", u"JD", System::DateTime::get_Today());
comment->SetText(u"Quisque fringilla leo.");
auto commentRangeStart = MakeObject<CommentRangeStart>(doc, comment->get_Id());
auto commentRangeEnd = MakeObject<CommentRangeEnd>(doc, comment->get_Id());
run->get_ParentNode()->InsertBefore(commentRangeStart, run);
run->get_ParentNode()->InsertAfter(commentRangeEnd, run);
commentRangeEnd->get_ParentNode()->InsertAfter(comment, commentRangeEnd);
comment->AddReply(u"Jane Doe", u"JD", System::DateTime::get_Now(),
u"Pellentesque vel sapien justo.");
doc->Save(u"Output.docx");
using namespace Aspose::Words;
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto firstRun = MakeObject<Run>(doc, u"Proin eros metus, sagittis sed. ");
auto secondRun = MakeObject<Run>(doc, u"Morbi enim nunc faucibus a.");
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(firstRun);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(secondRun);
builder->MoveTo(secondRun);
builder->StartBookmark(u"Aspose bookmark");
// Yen NextSibling null, banjur paling kamungkinan iki Run pungkasan ing Paragraf.
if (secondRun->get_NextSibling() != NULL)
builder->MoveTo(secondRun->get_NextSibling());
else
builder->MoveTo(secondRun->get_ParentParagraph());
builder->EndBookmark(u"Aspose bookmark");
doc->Save(u"Output.docx");
using namespace Aspose::Words;
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto firstRun = MakeObject<Run>(doc, u"Proin eros metus, sagittis sed. ");
auto secondRun = MakeObject<Run>(doc, u"Morbi enim nunc faucibus a.");
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(firstRun);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(secondRun);
builder->MoveTo(secondRun);
builder->StartBookmark(u"Aspose bookmark");
// Yen NextSibling null, banjur paling kamungkinan iki Run pungkasan ing Paragraf.
if (secondRun->get_NextSibling() != NULL)
builder->MoveTo(secondRun->get_NextSibling());
else
builder->MoveTo(secondRun->get_ParentParagraph());
builder->EndBookmark(u"Aspose bookmark");
auto saveOptions = MakeObject<PdfSaveOptions>();
saveOptions->get_OutlineOptions()->get_BookmarksOutlineLevels()->Add(u"Aspose bookmark", 1);
doc->Save(u"Output.docx", saveOptions);
using namespace Aspose::Words;
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto firstRun = MakeObject<Run>(doc, u"Proin eros metus, sagittis sed. ");
auto secondRun = MakeObject<Run>(doc, u"Morbi enim nunc faucibus a.");
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(firstRun);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(secondRun);
builder->MoveTo(secondRun);
builder->StartBookmark(u"Aspose bookmark");
// Yen NextSibling null, banjur paling kamungkinan iki Run pungkasan ing Paragraf.
if (secondRun->get_NextSibling() != NULL)
builder->MoveTo(secondRun->get_NextSibling());
else
builder->MoveTo(secondRun->get_ParentParagraph());
builder->EndBookmark(u"Aspose bookmark");
doc->Save(u"Output.docx");
using namespace Aspose::Words;
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto firstRun = MakeObject<Run>(doc, u"Proin eros metus, sagittis sed. ");
auto secondRun = MakeObject<Run>(doc, u"Morbi enim nunc faucibus a.");
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(firstRun);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(secondRun);
builder->MoveTo(secondRun);
builder->StartBookmark(u"Aspose bookmark");
// Yen NextSibling null, banjur paling kamungkinan iki Run pungkasan ing Paragraf.
if (secondRun->get_NextSibling() != NULL)
builder->MoveTo(secondRun->get_NextSibling());
else
builder->MoveTo(secondRun->get_ParentParagraph());
builder->EndBookmark(u"Aspose bookmark");
doc->Save(u"Output.docx");
using namespace Aspose::Words;
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto firstRun = MakeObject<Run>(doc, u"Proin eros metus, sagittis sed. ");
auto secondRun = MakeObject<Run>(doc, u"Morbi enim nunc faucibus a.");
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(firstRun);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(secondRun);
builder->MoveTo(secondRun);
builder->StartBookmark(u"Aspose bookmark");
// Yen NextSibling null, banjur paling kamungkinan iki Run pungkasan ing Paragraf.
if (secondRun->get_NextSibling() != NULL)
builder->MoveTo(secondRun->get_NextSibling());
else
builder->MoveTo(secondRun->get_ParentParagraph());
builder->EndBookmark(u"Aspose bookmark");
auto saveOptions = MakeObject<PdfSaveOptions>();
saveOptions->get_OutlineOptions()->get_BookmarksOutlineLevels()->Add(u"Aspose bookmark", 1);
doc->Save(u"Output.docx", saveOptions);
using namespace Aspose::Words;
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto shape = builder->InsertChart(ChartType::Pie, 432, 252);
auto chart = shape->get_Chart();
chart->get_Title()->set_Text(u"Demo Chart");
chart->get_Series()->Clear();
chart->get_Series()->Add(u"Series 1",
MakeArray<String>({ u"Category1", u"Category2", u"Category3" }),
MakeArray<double>({ 2.7, 3.2, 0.8 }));
doc->Save(u"Output.docx");
using namespace Aspose::Words;
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto firstRun = MakeObject<Run>(doc, u"Proin eros metus, sagittis sed. ");
auto secondRun = MakeObject<Run>(doc, u"Morbi enim nunc faucibus a.");
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(firstRun);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(secondRun);
builder->MoveTo(secondRun);
builder->StartBookmark(u"Aspose bookmark");
// Yen NextSibling null, banjur paling kamungkinan iki Run pungkasan ing Paragraf.
if (secondRun->get_NextSibling() != NULL)
builder->MoveTo(secondRun->get_NextSibling());
else
builder->MoveTo(secondRun->get_ParentParagraph());
builder->EndBookmark(u"Aspose bookmark");
doc->Save(u"Output.docx");
using namespace Aspose::Words;
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto firstRun = MakeObject<Run>(doc, u"Proin eros metus, sagittis sed. ");
auto secondRun = MakeObject<Run>(doc, u"Morbi enim nunc faucibus a.");
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(firstRun);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(secondRun);
builder->MoveTo(secondRun);
builder->StartBookmark(u"Aspose bookmark");
// Yen NextSibling null, banjur paling kamungkinan iki Run pungkasan ing Paragraf.
if (secondRun->get_NextSibling() != NULL)
builder->MoveTo(secondRun->get_NextSibling());
else
builder->MoveTo(secondRun->get_ParentParagraph());
builder->EndBookmark(u"Aspose bookmark");
auto saveOptions = MakeObject<PdfSaveOptions>();
saveOptions->get_OutlineOptions()->get_BookmarksOutlineLevels()->Add(u"Aspose bookmark", 1);
doc->Save(u"Output.docx", saveOptions);
Ana telung opsi kanggo nginstal Aspose.Words for C++ kanggo lingkungan pangembang. Pilih salah siji sing cocog karo kabutuhan sampeyan lan tindakake pandhuan langkah demi langkah:
Sampeyan bisa nggunakake perpustakaan C++ iki kanggo nggawe piranti lunak ing Microsoft Windows, Linux lan macOS:
Yen sampeyan nggawe piranti lunak kanggo Linux utawa macOS, priksa informasi babagan katergantungan perpustakaan tambahan (fontconfig lan paket sumber terbuka mesa-glu) ing Dokumentasi Produk.