Aspose.Words使用教程之如何寫入純文本(TXT)文件

  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.ReflectionImports 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.DirectorySeparatorCharDim 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功能而不是純文本。

下表顯示了文本導入引擎的關鍵特性:

FeatureDetails
Text encodingThe following encoding are supported:
Latin1
BigEndianUnicode
UTF-16
UTF-7
UTF-8
Import of ordered lists1.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 listsUnordered lists are imported from consecutive lines which start with any of the following characters: *,--,  o, .
Paragraph indentationLeft indent and first line indent are detected and imported for paragraphs using appropriate number space characters at the beginning of the paragraph.
Paragraph detectionRules 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.Words

輸出文檔

文本文件加載到Aspose的結果,保存爲如下文檔。

注意,前面的空間解釋爲縮進,列表被加載適當的列表功能。

Aspose.Words

查看更多Aspose.Words使用教程

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章