การทำงานกับเอกสารข้อความ
ในบทความนี้เราจะเรียนรู้ว่าตัวเลือกใดจะมีประโยชน์สำหรับการทำงานกับเอกสารข้อความผ่านAspose.Words โปรดทราบว่านี้ไม่ได้เป็นรายการที่สมบูรณ์ของตัวเลือกที่มีอยู่แต่เพียงตัวอย่างของการทำง.
เพิ่มเครื่องหมายสองทิศทาง
คุณสามารถใช้คุณสมบัติAddBidiMarksเพื่อระบุว่าจะเพิ่มเครื่องหมายสองทิศทางก่อนที่แต่ละรายการBiDiรัน Aspose.Wordsแทรกอักขระยูนิโค้ด’RIGHT-TO-LEFT MARK' (200)ก่อนที่จะทำงานในแต่ละสองทิศทางในข้อความ ตัวเลือกนี้สอดคล้องกับตัวเลือก"เพิ่มเครื่องหมายสองทิศทาง"ในกล่องโต้ตอบการแปลงไฟล์MSคำเมื่อคุณส่งออกไปยังรูปแบบข้อความธรรมดา โปรดทราบว่าปรากฏในกล่องโต้ตอบก็ต่อเมื่อมีการเพิ่มภาษาการแก้ไขภาษาอาหรับหรือภาษาฮิบรูในคำMS.
ตัวอย่างรหัสต่อไปนี้แสดงวิธีใช้คุณสมบัติAddBidiMarks ค่าดีฟอลต์ของคุณสมบัตินี้คือfalse:
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"Input.docx"); | |
System::SharedPtr<TxtSaveOptions> saveOptions = System::MakeObject<TxtSaveOptions>(); | |
saveOptions->set_AddBidiMarks(true); | |
System::String outputPath = outputDataDir + u"WorkingWithTxt.AddBidiMarks.txt"; | |
doc->Save(outputPath, saveOptions); |
รู้จักรายการในระหว่างการโหลดTXT
Aspose.Wordsสามารถนำเข้ารายการของไฟล์ข้อความเป็นหมายเลขรายการหรือข้อความธรรมดาใน คุณสมบัติDetectNumberingWithWhitespacesอนุญาตให้ระบุวิธีการจดจำรายการที่มีหมายเลขเมื่อเอกสารถูกนำเข้าจากรูปแบบข้อความธรรมดา:
- หากตั้งค่าตัวเลือกนี้เป็นtrue ช่องว่างจะถูกใช้เป็นตัวคั่นหมายเลขรายการด้วย:อัลกอริทึมการรู้จำรายการสำหรับหมายเลขสไตล์อาหรับ(1, 1.1.2.)ใช้ทั้งช่องว่างและจุด(".")สัญลักษณ์.
- หากตั้งค่าตัวเลือกนี้เป็นfalseอัลกอริทึมการจดจำจะตรวจจับย่อหน้าของรายการเมื่อหมายเลขรายการจบลงด้วยจุดใดจุดวงเล็บด้านขวาหรือสัญลักษณ์แสดงหัวข้อย่อย(เช่น"•", “*”, “-” หรือ"o").
ตัวอย่างรหัสต่อไปนี้แสดงวิธีใช้คุณสมบัตินี้:
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
System::SharedPtr<TxtLoadOptions> loadOptions = System::MakeObject<TxtLoadOptions>(); | |
loadOptions->set_DetectNumberingWithWhitespaces(false); | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"LoadTxt.txt", loadOptions); | |
System::String outputPath = outputDataDir + u"WorkingWithTxt.DetectNumberingWithWhitespaces.docx"; | |
doc->Save(outputPath); |
วิธีการจัดการช่องว่างชั้นนำและต่อท้ายระหว่างการโหลดTXT
คุณสามารถควบคุมวิธีการจัดการช่องว่างชั้นนำและต่อท้ายระหว่างการโหลดไฟล์TXT พื้นที่ชั้นนำสามารถตัด,เก็บรักษาหรือแปลงเป็นเยื้องและช่องว่างต่อท้ายสามารถตัดหรือเก็บรักษาไว้.
ตัวอย่างรหัสต่อไปนี้แสดงวิธีการตัดแต่งช่องว่างชั้นนำและต่อท้ายขณะนำเข้าไฟล์TXT:
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
System::SharedPtr<TxtLoadOptions> loadOptions = System::MakeObject<TxtLoadOptions>(); | |
loadOptions->set_LeadingSpacesOptions(TxtLeadingSpacesOptions::Trim); | |
loadOptions->set_TrailingSpacesOptions(TxtTrailingSpacesOptions::Trim); | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"LoadTxt.txt", loadOptions); | |
System::String outputPath = outputDataDir + u"WorkingWithTxt.HandleSpacesOptions.docx"; | |
doc->Save(outputPath); |
ส่งออกส่วนหัวและส่วนท้ายในการส่งออกTXT
ถ้าคุณต้องการส่งออกส่วนหัวและส่วนท้ายในเอกสารออกTXTคุณสามารถใช้คุณสมบัติExportHeadersFootersMode คุณสมบัตินี้ระบุวิธีเอ็กซ์พอร์ตส่วนหัวและท้ายกระดาษไปยังรูปแบบข้อความธรรมดา.
ตัวอย่างรหัสต่อไปนี้แสดงวิธีการส่งออกส่วนหัวและท้ายกระดาษไปยังรูปแบบข้อความล้วน:
การเยื้องรายการส่งออกในผลลัพธ์TXT
Aspose.WordsแนะนำTxtListIndentationคลาสที่อนุญาตให้ระบุว่าระดับรายการจะเยื้องในขณะที่ส่งออกไปยังรูปแบบข้อค ขณะทำงานกับTxtSaveOptionคุณสมบัติListIndentationจะถูกจัดเตรียมไว้เพื่อระบุอักขระที่จะใช้สำหรับการเยื้องระดับร.
ค่าดีฟอลต์สำหรับคุณสมบัติอักขระคือ'\0’แสดงว่าไม่มีการเยื้อง สำหรับคุณสมบัติการนับค่าดีฟอลต์คือ0ซึ่งหมายความว่าไม่มีการเยื้อง.
ใช้อักขระแท็บ
ตัวอย่างรหัสต่อไปนี้แสดงวิธีการส่งออกระดับรายการโดยใช้อักขระแท็บ:
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"input_document"); | |
System::SharedPtr<TxtSaveOptions> options = System::MakeObject<TxtSaveOptions>(); | |
options->get_ListIndentation()->set_Count(1); | |
options->get_ListIndentation()->set_Character(u'\t'); | |
doc->Save(outputDataDir + u"WorkingWithTxt.UseTabCharacterPerLevelForListIndentation.txt", options); |
ใช้อักขระพื้นที่
ตัวอย่างรหัสต่อไปนี้แสดงวิธีการส่งออกระดับรายการโดยใช้อักขระพื้นที่:
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"input_document"); | |
System::SharedPtr<TxtSaveOptions> options = System::MakeObject<TxtSaveOptions>(); | |
options->get_ListIndentation()->set_Count(3); | |
options->get_ListIndentation()->set_Character(u' '); | |
doc->Save(outputDataDir + u"WorkingWithTxt.UseSpaceCharacterPerLevelForListIndentation.txt", options); |
การใช้การเยื้องปริยาย
ตัวอย่างรหัสต่อไปนี้แสดงวิธีการส่งออกระดับรายการโดยใช้การเยื้องเริ่มต้น:
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
System::SharedPtr<Document> doc1 = System::MakeObject<Document>(inputDataDir + u"input_document"); | |
doc1->Save(outputDataDir + u"WorkingWithTxt.DefaultLevelForListIndentation1.txt"); | |
//Document doc2 = new Document("input_document"); | |
System::SharedPtr<Document> doc2 = System::MakeObject<Document>(inputDataDir + u"Input.docx"); | |
System::SharedPtr<TxtSaveOptions> options = System::MakeObject<TxtSaveOptions>(); | |
doc2->Save(outputDataDir + u"WorkingWithTxt.DefaultLevelForListIndentation2.txt", options); |