สร้าง HTML โดยใช้ C++ ห้องสมุด

ไลบรารี C++ อันทรงพลังของเราช่วยให้นักพัฒนาสามารถสร้าง HTML แบบเป็นโปรแกรมได้ภายในไม่กี่ขั้นตอน

C++ นักพัฒนาสามารถสร้าง HTML ได้อย่างง่ายดายโดยใช้เฉพาะ API ผลิตภัณฑ์ที่มีประสิทธิภาพของเรา หมายความว่าโซลูชันของเราจะมอบทุกสิ่งที่จำเป็นสำหรับโปรแกรมเมอร์ในการสร้าง HTML ใน C++

ดูข้อมูลโค้ด

สร้าง HTML ใน C++ โดยทางโปรแกรม

ด้วยนักพัฒนาไลบรารี C++ ของเรา นักพัฒนาสามารถสร้าง HTML ตั้งแต่เริ่มต้นได้อย่างง่ายดาย ในการดำเนินการนี้ นักพัฒนา C++ ต้องดำเนินการเพียงไม่กี่ขั้นตอน:

  1. เพิ่มชื่อไฟล์
  2. เริ่มสร้างเอกสาร HTML โดยใช้ C++
  3. บันทึกไฟล์ HTML ที่ส่งออก

เป็นที่น่าสังเกตว่าเอกสารเปล่าควรจะมีหนึ่งย่อหน้าในทางเทคนิค ดังนั้นเมื่อคุณสร้างเอกสาร HTML โดยทางโปรแกรม คุณจะได้โครงสร้างเอกสารพื้นฐานที่แน่นอน

โปรดทราบว่าคุณสามารถเพิ่มเนื้อหาลงในไฟล์ HTML ที่สร้างขึ้นใหม่ได้ทันที ดังนั้น คุณจะได้ไม่เพียงแค่เอกสารเปล่า แต่ได้เอกสารที่มีเนื้อหาที่จำเป็น สำหรับข้อมูลเพิ่มเติมเกี่ยวกับวิธีการแก้ไขเอกสาร โปรดดูที่หน้าการแก้ไข

สร้าง HTML ใน C++

ไลบรารี C++ นี้ช่วยให้คุณสร้างเอกสาร HTML โดยทางโปรแกรม ลองใช้ฟังก์ชันอันทรงพลังของเรา และดูวิธีสร้าง HTML ในบางรูปแบบโดยใช้ตัวอย่างต่อไปนี้:

สร้าง HTML ใหม่โดยใช้ C++
เลือกรูปแบบเป้าหมายจากรายการ
รันโค้ด
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.html");
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"); // ถ้า NextSibling เป็นโมฆะ เป็นไปได้มากว่านี่คือ Run สุดท้ายในย่อหน้า 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.html"); 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"); // ถ้า NextSibling เป็นโมฆะ เป็นไปได้มากว่านี่คือ Run สุดท้ายในย่อหน้า 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.html", 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.html");
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"); // ถ้า NextSibling เป็นโมฆะ เป็นไปได้มากว่านี่คือ Run สุดท้ายในย่อหน้า 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.html"); 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"); // ถ้า NextSibling เป็นโมฆะ เป็นไปได้มากว่านี่คือ Run สุดท้ายในย่อหน้า 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.html", 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");
// ถ้า NextSibling เป็นโมฆะ เป็นไปได้มากว่านี่คือ Run สุดท้ายในย่อหน้า
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.html");
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"); // ถ้า NextSibling เป็นโมฆะ เป็นไปได้มากว่านี่คือ Run สุดท้ายในย่อหน้า 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.html"); 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"); // ถ้า NextSibling เป็นโมฆะ เป็นไปได้มากว่านี่คือ Run สุดท้ายในย่อหน้า 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.html", 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.html");
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"); // ถ้า NextSibling เป็นโมฆะ เป็นไปได้มากว่านี่คือ Run สุดท้ายในย่อหน้า 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.html"); 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"); // ถ้า NextSibling เป็นโมฆะ เป็นไปได้มากว่านี่คือ Run สุดท้ายในย่อหน้า 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.html", saveOptions);
รันโค้ด

วิธีสร้าง HTML ใน C++

  1. ติดตั้ง Aspose.Words for C++
  2. เพิ่มการอ้างอิงไลบรารี (นำเข้าไลบรารี) ไปยัง C++ โครงการของคุณ
  3. สร้างเอกสาร HTML ใหม่
  4. เรียกเมธอด Save() โดยส่งชื่อไฟล์
  5. รับผลลัพธ์เป็นไฟล์แยกต่างหาก

C++ ไลบรารีเพื่อสร้าง HTML

มีสามตัวเลือกในการติดตั้ง Aspose.Words for C++ ในสภาพแวดล้อมของนักพัฒนาซอฟต์แวร์ของคุณ โปรดเลือกหนึ่งรายการที่ตรงกับความต้องการของคุณและทำตามคำแนะนำทีละขั้นตอน:

ความต้องการของระบบ

คุณสามารถใช้ไลบรารี C++ นี้เพื่อพัฒนาซอฟต์แวร์บน Microsoft Windows, Linux และ macOS:

  • GCC >= 6.3.0 และ Clang >= 3.9.1 จำเป็นสำหรับ Linux
  • Xcode >= 12.5.1 Clang และ libc++ สำหรับ macOS

หากคุณพัฒนาซอฟต์แวร์สำหรับ Linux หรือ macOS โปรดตรวจสอบข้อมูลเกี่ยวกับการพึ่งพาไลบรารีเพิ่มเติม (แพ็คเกจโอเพ่นซอร์ส fontconfig และ mesa-glu) ในเอกสารประกอบผลิตภัณฑ์

รูปแบบไฟล์อื่นๆ ที่รองรับ

คุณสามารถสร้างเอกสารในรูปแบบไฟล์อื่น:

5%

สมัครสมาชิก Aspose Product Updates

รับจดหมายข่าวและข้อเสนอรายเดือนที่ส่งตรงถึงกล่องจดหมายของคุณ