文檔首頁>>Aspose.Words使用教程>>Aspose.Words使用教程之如何寫入純文本(TXT)文件
Aspose.Words使用教程之如何寫入純文本(TXT)文件
Aspose.Words通過使用[Document]構(gòu)造函數(shù)可以和其他文檔格式一樣輸入純文本數(shù)據(jù)。
Example
輸入一個純文本文件到一個Aspose.Words文檔對象里面。
C#
using System; using System.IO; using System.Reflection; using System.Text; using Aspose.Words; namespace LoadTxt { class Program { public static void Main(string[] args) { // Sample infrastructure. string exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar; string dataDir = new Uri(new Uri(exeDir), @"../../Data/").LocalPath; // The encoding of the text file is automatically detected. Document doc = new Document(dataDir + "LoadTxt.txt"); // Save as any Aspose.Words supported format, such as DOCX. doc.Save(dataDir + "LoadTxt Out.docx"); } } }
Visual Basic
Imports Microsoft.VisualBasic Imports System Imports System.IO Imports System.Reflection Imports System.Text Imports Aspose.Words Namespace LoadTxt Friend Class Program Public Shared Sub Main(ByVal args() As String) ' Sample infrastructure. Dim exeDir As String = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar Dim dataDir As String = New Uri(New Uri(exeDir), "../../Data/").LocalPath ' The encoding of the text file is automatically detected. Dim doc As New Document(dataDir & "LoadTxt.txt") ' Save as any Aspose.Words supported format, such as DOCX. doc.Save(dataDir & "LoadTxt Out.docx") End Sub End Class End Namespace
文本導(dǎo)入功能
純文本格式是一種基本的格式,不需要高級的文本處理器查看或編輯,然而一些純文本文件試圖證明更復(fù)雜的格式例如列表和縮進(jìn)。例如列表可以表示為一系列每個從相同的字符開始的線。
Aspose.Words試圖檢測和加載一些特性進(jìn)入一個新文檔例如等價的Microsoft word功能而不是純文本。
下表顯示了文本導(dǎo)入引擎的關(guān)鍵特性:
Feature | Details |
Text encoding | The following encoding are supported: Latin1 BigEndianUnicode UTF-16 UTF-7 UTF-8 |
Import of ordered lists | 1.Arabic number with dot or right parenthesis e.g 1. or 2). Multilevel list are supported only supported when using dot. 2.Uppercase or lowercase Latin letter with dot or right parenthesis e.g a. or b). |
Import of unordered lists | Unordered lists are imported from consecutive lines which start with any of the following characters: *,--, o, •. |
Paragraph indentation | Left indent and first line indent are detected and imported for paragraphs using appropriate number space characters at the beginning of the paragraph. |
Paragraph detection | Rules for detecting a new paragraph start: 1.If next line left indent isn’t equal with the current paragraph’s left indent. 2.An empty line starts a new paragraph. 3.Any list detected starts a new paragraph. |
樣本轉(zhuǎn)換
樣本輸入(純文本文件)
輸出文檔
文本文件加載到Aspose的結(jié)果,保存為如下文檔。
注意,前面的空間解釋為縮進(jìn),列表被加載適當(dāng)?shù)牧斜砉δ堋?/p>