สวัสดีชาวโลก!
“สวัสดีชาวโลก!” โค้ดมักเป็นตัวอย่างง่ายๆ ตัวแรกในการเขียน uisng “Aspose.Words for .NET” และยังสามารถใช้เป็นการทดสอบสติเพื่อให้แน่ใจว่าซอฟต์แวร์ที่ตั้งใจจะคอมไพล์หรือรันซอร์สโค้ดได้รับการติดตั้งอย่างถูกต้อง
ไลบรารี C# “Aspose.Words สำหรับ .NET” ช่วยให้นักพัฒนาสามารถเข้าถึงโดยตรงเพื่อสร้าง แก้ไข ผสาน แปลง เปรียบเทียบเอกสาร Word และเว็บ PDF, DOCX, DOC, RTF, ODT, EPUB, HTML และรูปแบบไฟล์อื่นๆ อีกมากมายคือ รูปแบบเอกสารที่รองรับ
ข้อมูลโค้ด Below code ทำตามขั้นตอนเหล่านี้:
- สร้าง Document ว่างใหม่
- เริ่มต้นคลาส DocumentBuilder
- แทรกข้อความลงในเอกสารโดยเริ่มโดยใช้วิธี Write แบบง่าย
- เปิด Document ที่มีอยู่จากไฟล์ ตรวจจับรูปแบบไฟล์โดยอัตโนมัติ
- เอกสาร Append “A” ถึงและของเอกสาร “B”
- Save เอาต์พุตเป็น PDF
ข้อมูลโค้ดต่อไปนี้คือ “Hello, World!” ตัวอย่างเพื่อแสดงการทำงานของ API “Aspose.Words for .NET”:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET.git. | |
Document docA = new Document(); | |
DocumentBuilder builder = new DocumentBuilder(docA); | |
// Insert text to the document start. | |
builder.MoveToDocumentStart(); | |
builder.Write("First Hello World paragraph"); | |
Document docB = new Document(MyDir + "Document.docx"); | |
// Add document B to the and of document A, preserving document B formatting. | |
docA.AppendDocument(docB, ImportFormatMode.KeepSourceFormatting); | |
docA.Save(ArtifactsDir + "HelloWorld.SimpleHelloWorld.pdf"); |