Wednesday, 13 July 2011 06:07

How to Convert Word to Text

Written by  support iceblue
Rate this item
(0 votes)

Why We Convert Word to Text?

Text is a format usually contains plain text or with minimum formatting. We can get benefits from Word to Text conversion:

  • Much smaller file size to save disk space
  • Compatible with almost all applications
  • Without or with minimum formatting and/or unusual characters

How to Convert Word to Text?

Spire.Doc is a MS Word component which enables user to perform a wide range of Word document processing tasks directly, such as generate, read, write and modify Word document for .NET and Silverlight. It supports converting files from Word Doc to Text, HTML, PDF, XML, RTF, Docx, Dot, etc.

 

Download Spire.Doc (or Spire.Office) with .NET Framework 2.0 (or above) together and follow the simple code below to convert Word to Text.

 

Step 1

Create a project in Visual Studio. Add Spire.Doc DLL as reference.

Step 2

Use the following code to load local Word docfile which you want to convert to Txt file.

            Document document = new Document();
            document.LoadFromFile(@"D:\Work\Stephen\2011.12.05\Sample.doc");

Step 3

Save the word doc file as HTML by using the code below:

            document.SaveToFile("Sample.txt", FileFormat.Txt);

Step 4

Write the following full code into your project and press F5 to start it. Then, a Txt file will be automatically generated.

Convert Word to Text with C# Code:

[C#]
using System;
using System.Windows.Forms;
using Spire.Doc;
using Spire.Doc.Documents;

namespace tohtml_3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Create word document
            Document document = new Document();
            document.LoadFromFile(@"D:\Work\Stephen\2011.12.05\Sample.doc");

            //Save doc file.
            document.SaveToFile("Sample.txt", FileFormat.Txt);

            //Launching the MS Word file.
            WordDocViewer("Sample.txt");
        }

        private void WordDocViewer(string fileName)
        {
            try
            {
                System.Diagnostics.Process.Start(fileName);
            }
            catch { }
        }

    }
}
     

Convert Word to Text with VB.NET Code:

[VB.NET]
Imports System
Imports System.Windows.Forms
Imports Spire.Doc
Imports Spire.Doc.Documents

Namespace tohtml_3
	Partial Public Class Form1
		Inherits Form
		Public Sub New()
			InitializeComponent()
		End Sub

		Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
			'Create word document
			Dim document As New Document()
			document.LoadFromFile("D:\Work\Stephen\2011.12.05\Sample.doc")

			'Save doc file.
			document.SaveToFile("Sample.txt", FileFormat.Txt)

			'Launching the MS Word file.
			WordDocViewer("Sample.txt")
		End Sub

		Private Sub WordDocViewer(ByVal fileName As String)
			Try
				System.Diagnostics.Process.Start(fileName)
			Catch
			End Try
		End Sub

	End Class
End Namespace

Effective Screenshot

Word to Text

Additional Info

  • tutorial_title: Convert Word to Text
Last modified on Wednesday, 08 January 2014 03:04