Aspose.words How to write a plain text (TXT) file using the tutorial

Source: Internet
Author: User

aspose.words can Enter plain text data just like other document formats by using the [document] constructor.

Example

Enter a plain text file to a aspose.words Inside the Document object .

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.textimports aspose.wordsnamespace 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

Text Import feature

Plain Text Format is a basic format that does not require advanced text processor viewing or editing, However, some plain text files try to prove more complex formats such as lists and indents. For example, a list can be represented as a series of lines that start with the same characters.

Aspose.words attempts to detect and load some features into a new document such as equivalent Microsoft Word functionality instead of plain text.

The following table shows the key features of the text import engine:

Feature Details
Text encoding The following encoding is 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 is 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 is imported from consecutive lines which start with any of the following characters: *,--, O,.
Paragraph Indentation Left indent and first line indent is detected and imported for paragraphs using appropriate number space characters at th E beginning of the paragraph.
Paragraph detection Rules for detecting a new paragraph start:
1.If Next line left indent is ' 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.

Sample Conversion

Sample input (plain text file)

650) this.width=650; "alt=" Aspose.words "class=" img-thumbnail01 "src=" http://image.evget.com/images/article/2015/ Sample01_input.jpg "/>

Output document

The text file is loaded into the aspose result, saved as the following document.

Note that the preceding space is interpreted as indentation, and the list is loaded with the appropriate list feature.

650) this.width=650; "alt=" Aspose.words "class=" img-thumbnail02 "src=" http://image.evget.com/images/article/2015/ Sample02_output.jpg "/>

See more Aspose.words Tutorials

Aspose.words How to write a plain text (TXT) file using the tutorial

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.