原創|使用教程|編輯:龔雪|2015-08-26 09:04:34.000|閱讀 1248 次
概述:Aspose.Words使用教程之如何寫入純文本(TXT)文件
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Aspose.Words通過使用[Document]構造函數可以和其他文檔格式一樣輸入純文本數據。
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
文本導入功能
純文本格式是一種基本的格式,不需要高級的文本處理器查看或編輯,然而一些純文本文件試圖證明更復雜的格式例如列表和縮進。例如列表可以表示為一系列每個從相同的字符開始的線。
Aspose.Words試圖檢測和加載一些特性進入一個新文檔例如等價的Microsoft word功能而不是純文本。
下表顯示了文本導入引擎的關鍵特性:
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. |
樣本轉換
樣本輸入(純文本文件)
輸出文檔
文本文件加載到Aspose的結果,保存為如下文檔。
注意,前面的空間解釋為縮進,列表被加載適當的列表功能。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網