สร้าง Word โดยใช้ Node.js via .NET ห้องสมุด

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

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

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

สร้าง Word ใน JavaScript โดยทางโปรแกรม

ด้วยนักพัฒนาไลบรารี JavaScript ของเรา นักพัฒนาสามารถสร้าง Word ตั้งแต่เริ่มต้นได้อย่างง่ายดาย ในการดำเนินการนี้ นักพัฒนา Node.js via .NET ต้องดำเนินการเพียงไม่กี่ขั้นตอน:

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

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

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

สร้าง Word ใน JavaScript

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

สร้าง DOCX ใหม่โดยใช้ JavaScript
เลือกรูปแบบเป้าหมายจากรายการ
รันโค้ด
npm install @aspose/words
สำเนา
const aw = require('@aspose/words');

var doc = new aw.Document()
var builder = new aw.DocumentBuilder(doc)

font = builder.font
font.name = "Courier New"
font.color = '#FF0000'
font.size = 36
font.highlightColor = '#F0DB4F'

builder.write("Morbi enim nunc faucibus a.")

doc.save("Output.docx")
const aw = require('@aspose/words'); var doc = new aw.Document() var builder = new aw.DocumentBuilder(doc) var firstRun = new aw.Run(doc, "Proin eros metus, sagittis sed. ") var secondRun = new aw.Run(doc, "Morbi enim nunc faucibus a.") doc.firstSection.body.firstParagraph.appendChild(firstRun) doc.firstSection.body.firstParagraph.appendChild(secondRun) builder.moveTo(secondRun) builder.startBookmark("Aspose bookmark") // หากNextSiblingเป็นโมฆะ,แล้วส่วนใหญ่นี้เป็นรันสุดท้ายในย่อหน้า. if (secondRun.nextSibling != null) builder.moveTo(secondRun.nextSibling) else builder.moveTo(secondRun.parentParagraph) builder.endBookmark("Aspose bookmark") doc.save("Output.docx") const aw = require('@aspose/words'); var doc = new aw.Document() var builder = new aw.DocumentBuilder(doc) var firstRun = new aw.Run(doc, "Proin eros metus, sagittis sed. ") var secondRun = new aw.Run(doc, "Morbi enim nunc faucibus a.") doc.firstSection.body.firstParagraph.appendChild(firstRun) doc.firstSection.body.firstParagraph.appendChild(secondRun) builder.moveTo(secondRun) builder.startBookmark("Aspose bookmark") // หากNextSiblingเป็นโมฆะ,แล้วส่วนใหญ่นี้เป็นรันสุดท้ายในย่อหน้า. if (secondRun.nextSibling != null) builder.moveTo(secondRun.nextSibling) else builder.moveTo(secondRun.parentParagraph) builder.endBookmark("Aspose bookmark") var saveOptions = new aw.Saving.PdfSaveOptions() saveOptions.outlineOptions.bookmarksOutlineLevels.add("Aspose bookmark", 1); doc.save("Output.docx", saveOptions)
const aw = require('@aspose/words');

var doc = new aw.Document()

var run = new aw.Run(doc, "Proin eros metus, sagittis sed.")
var para = doc.firstSection.body.firstParagraph
para.appendChild(run)

var comment = new aw.Comment(doc)
comment.author = "John Doe"
comment.initial = "JD"
comment.dateTime = new Date()
comment.setText("Quisque fringilla leo.")

var commentRangeStart = new aw.CommentRangeStart(doc, comment.id)
var commentRangeEnd = new aw.CommentRangeEnd(doc, comment.id)

run.parentNode.insertBefore(commentRangeStart, run)
run.parentNode.insertAfter(commentRangeEnd, run)
commentRangeEnd.parentNode.insertAfter(comment, commentRangeEnd)

comment.addReply("Jane Doe", "JD", new Date(), "Pellentesque vel sapien justo.")

doc.save("Output.docx")
const aw = require('@aspose/words'); var doc = new aw.Document() var builder = new aw.DocumentBuilder(doc) var firstRun = new aw.Run(doc, "Proin eros metus, sagittis sed. ") var secondRun = new aw.Run(doc, "Morbi enim nunc faucibus a.") doc.firstSection.body.firstParagraph.appendChild(firstRun) doc.firstSection.body.firstParagraph.appendChild(secondRun) builder.moveTo(secondRun) builder.startBookmark("Aspose bookmark") // หากNextSiblingเป็นโมฆะ,แล้วส่วนใหญ่นี้เป็นรันสุดท้ายในย่อหน้า. if (secondRun.nextSibling != null) builder.moveTo(secondRun.nextSibling) else builder.moveTo(secondRun.parentParagraph) builder.endBookmark("Aspose bookmark") doc.save("Output.docx") const aw = require('@aspose/words'); var doc = new aw.Document() var builder = new aw.DocumentBuilder(doc) var firstRun = new aw.Run(doc, "Proin eros metus, sagittis sed. ") var secondRun = new aw.Run(doc, "Morbi enim nunc faucibus a.") doc.firstSection.body.firstParagraph.appendChild(firstRun) doc.firstSection.body.firstParagraph.appendChild(secondRun) builder.moveTo(secondRun) builder.startBookmark("Aspose bookmark") // หากNextSiblingเป็นโมฆะ,แล้วส่วนใหญ่นี้เป็นรันสุดท้ายในย่อหน้า. if (secondRun.nextSibling != null) builder.moveTo(secondRun.nextSibling) else builder.moveTo(secondRun.parentParagraph) builder.endBookmark("Aspose bookmark") var saveOptions = new aw.Saving.PdfSaveOptions() saveOptions.outlineOptions.bookmarksOutlineLevels.add("Aspose bookmark", 1); doc.save("Output.docx", saveOptions)
const aw = require('@aspose/words');

var doc = new aw.Document()
var builder = new aw.DocumentBuilder(doc)

var firstRun = new aw.Run(doc, "Proin eros metus, sagittis sed. ")
var secondRun = new aw.Run(doc, "Morbi enim nunc faucibus a.")
doc.firstSection.body.firstParagraph.appendChild(firstRun)
doc.firstSection.body.firstParagraph.appendChild(secondRun)

builder.moveTo(secondRun)
builder.startBookmark("Aspose bookmark")
// หากNextSiblingเป็นโมฆะ,แล้วส่วนใหญ่นี้เป็นรันสุดท้ายในย่อหน้า.
if (secondRun.nextSibling != null)
    builder.moveTo(secondRun.nextSibling)
else
    builder.moveTo(secondRun.parentParagraph)
builder.endBookmark("Aspose bookmark")

doc.save("Output.docx")
const aw = require('@aspose/words'); var doc = new aw.Document() var builder = new aw.DocumentBuilder(doc) var firstRun = new aw.Run(doc, "Proin eros metus, sagittis sed. ") var secondRun = new aw.Run(doc, "Morbi enim nunc faucibus a.") doc.firstSection.body.firstParagraph.appendChild(firstRun) doc.firstSection.body.firstParagraph.appendChild(secondRun) builder.moveTo(secondRun) builder.startBookmark("Aspose bookmark") // หากNextSiblingเป็นโมฆะ,แล้วส่วนใหญ่นี้เป็นรันสุดท้ายในย่อหน้า. if (secondRun.nextSibling != null) builder.moveTo(secondRun.nextSibling) else builder.moveTo(secondRun.parentParagraph) builder.endBookmark("Aspose bookmark") doc.save("Output.docx") const aw = require('@aspose/words'); var doc = new aw.Document() var builder = new aw.DocumentBuilder(doc) var firstRun = new aw.Run(doc, "Proin eros metus, sagittis sed. ") var secondRun = new aw.Run(doc, "Morbi enim nunc faucibus a.") doc.firstSection.body.firstParagraph.appendChild(firstRun) doc.firstSection.body.firstParagraph.appendChild(secondRun) builder.moveTo(secondRun) builder.startBookmark("Aspose bookmark") // หากNextSiblingเป็นโมฆะ,แล้วส่วนใหญ่นี้เป็นรันสุดท้ายในย่อหน้า. if (secondRun.nextSibling != null) builder.moveTo(secondRun.nextSibling) else builder.moveTo(secondRun.parentParagraph) builder.endBookmark("Aspose bookmark") var saveOptions = new aw.Saving.PdfSaveOptions() saveOptions.outlineOptions.bookmarksOutlineLevels.add("Aspose bookmark", 1); doc.save("Output.docx", saveOptions)
const aw = require('@aspose/words');

var doc = new aw.Document()
var builder = new aw.DocumentBuilder(doc)

shape = builder.insertChart(aw.Drawing.Charts.ChartType.Pie, 432, 252)
chart = shape.chart
chart.title.text = "Demo Chart"

chart.series.clear()
chart.series.add("Series 1",
    ["Category1", "Category2", "Category3"],
    [2.7, 3.2, 0.8])

doc.save("Output.docx")
const aw = require('@aspose/words'); var doc = new aw.Document() var builder = new aw.DocumentBuilder(doc) var firstRun = new aw.Run(doc, "Proin eros metus, sagittis sed. ") var secondRun = new aw.Run(doc, "Morbi enim nunc faucibus a.") doc.firstSection.body.firstParagraph.appendChild(firstRun) doc.firstSection.body.firstParagraph.appendChild(secondRun) builder.moveTo(secondRun) builder.startBookmark("Aspose bookmark") // หากNextSiblingเป็นโมฆะ,แล้วส่วนใหญ่นี้เป็นรันสุดท้ายในย่อหน้า. if (secondRun.nextSibling != null) builder.moveTo(secondRun.nextSibling) else builder.moveTo(secondRun.parentParagraph) builder.endBookmark("Aspose bookmark") doc.save("Output.docx") const aw = require('@aspose/words'); var doc = new aw.Document() var builder = new aw.DocumentBuilder(doc) var firstRun = new aw.Run(doc, "Proin eros metus, sagittis sed. ") var secondRun = new aw.Run(doc, "Morbi enim nunc faucibus a.") doc.firstSection.body.firstParagraph.appendChild(firstRun) doc.firstSection.body.firstParagraph.appendChild(secondRun) builder.moveTo(secondRun) builder.startBookmark("Aspose bookmark") // หากNextSiblingเป็นโมฆะ,แล้วส่วนใหญ่นี้เป็นรันสุดท้ายในย่อหน้า. if (secondRun.nextSibling != null) builder.moveTo(secondRun.nextSibling) else builder.moveTo(secondRun.parentParagraph) builder.endBookmark("Aspose bookmark") var saveOptions = new aw.Saving.PdfSaveOptions() saveOptions.outlineOptions.bookmarksOutlineLevels.add("Aspose bookmark", 1); doc.save("Output.docx", saveOptions)
รันโค้ด

วิธีสร้าง Word ใน JavaScript

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

JavaScript ไลบรารีเพื่อสร้าง Word

We host our Node.js via .Net packages in NPM repositories. Please follow the step-by-step instructions on how to install "Aspose.Words for Node.js via .NET" to your developer environment.

System Requirements

This package is compatible with Node.js 14.17.0 or higher.

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

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

5%

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

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