Convert document to other formats in word document

  • NPOI
  • Spire.Doc
  • Download Sample Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NPOI.XWPF.UserModel;
using System.IO;

namespace NPOI
{
    class Program
    {
        static void Main(string[] args)
        {
            //Load document
            XWPFDocument doc = new XWPFDocument(new FileStream("../../../Data/Sample.doc", FileMode.Open));

            //Save the file
            using (FileStream sw = File.Create("ConvertedFile.docx"))
            {
                doc.Write(sw);
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Spire.Doc;

namespace Spire.Doc
{
    class Program
    {
        static void Main(string[] args)
        {
            //Load document
            Document doc = new Document();
            doc.LoadFromFile("../../../Data/Sample.doc");

            //Save the file to other format
            string fileName = "ConvertedFile";
            doc.SaveToFile(fileName+".xlsx",FileFormat.Docx2010);
            doc.SaveToFile(fileName+".pdf",FileFormat.PDF);
            doc.SaveToFile(fileName + ".txt", FileFormat.Txt);
            doc.SaveToFile(fileName + ".svg", FileFormat.SVG);
        }
    }
}