1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

C#とVB.NETでWordからXMLへの変換

Posted at

はじめに

XMLはデータの保存と転送に使用される通用のマークアップ言語です。この文書形式は、タグ、要素、属性、およびテキストで構成されています。Word文書をXML形式に変換することで、文書の内容、フォーマット、および構造をタグの形式で表現し、より柔軟なデータ処理と交換を実現することができます。

ツール

このライブラリは、無料でWordを作成、編集、変換することができますが、段落数の制限があります。または、有料版の製品の無料トライアルを申し込むこともできます。

有料版 :Spire.Doc for .NET

準備

  1. Free Spire.Doc for .NETをダウンロードします。
  2. Visual Studioで新しいプロジェクトを作成します。
  3. そのプロジェクトを開いた後、「Solution Explorer」>「References」>「Add Reference」>「Browse」を選択します。
  4. BINフォルダ内のDLLファイルを見つけて、「OK」をクリックします。

上記の手順で DLL ファイルをプロジェクトに簡単にインポートできます。

コード:

C#:

using System;
using Spire.Doc;

namespace WordtoXML
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Documentクラスのオブジェクトの作成
            Document document = new Document();

            //Word 文書を読み込みます
            document.LoadFromFile(@"sample.docx");

            //Word 文書を XML ファイルとして保存します
            document.SaveToFile("toXML.xml", FileFormat.Xml);
        }
    }
}

VB.NET:

Imports System
Imports Spire.Doc

Module Program
    Sub Main(args As String())
        'Documentクラスのオブジェクトの作成
        Dim document As New Document()

        'Word 文書を読み込みます
        document.LoadFromFile("sample.docx")

        'Word 文書を XML ファイルとして保存します
        document.SaveToFile("toXML.xml", FileFormat.Xml)
    End Sub
End Module

image.png
この方法では、Word 文書を XPSPDFHTML などの他のファイル形式に変換することもできます。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?