インサート形状
コンテンツ
[
隠れる
]このチュートリアルでは、Aspose.Words for .NET を使用して Word 文書に図形を挿入する方法について説明します。図形を使用すると、ドキュメントの外観とレイアウトを向上させることができます。
前提条件
このチュートリアルに従うには、以下が必要です。
- Aspose.Words for .NET ライブラリがインストールされています。
- C# と Word ドキュメントを使用したワード処理の基本的な知識。
ステップ 1: ドキュメント ディレクトリを設定する
まず、ドキュメント ディレクトリへのパスを設定します。交換する"YOUR DOCUMENT DIRECTORY"
ドキュメントを保存するディレクトリへの実際のパスを指定します。
string dataDir = "YOUR DOCUMENT DIRECTORY";
ステップ 2: 新しいドキュメントと DocumentBuilder を作成する
の新しいインスタンスを作成します。Document
クラスとDocumentBuilder
ドキュメントを操作するオブジェクト。
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
ステップ 3: 図形を挿入する
使用InsertShape
の方法DocumentBuilder
オブジェクトを使用して図形をドキュメントに挿入します。形状のタイプ、相対的な水平および垂直位置、ページの寸法、サイズ、および折り返しのタイプを指定します。必要に応じて、図形の回転角度を設定することもできます。
Shape shape = builder.InsertShape(ShapeType.TextBox, RelativeHorizontalPosition.Page, 100,
RelativeVerticalPosition.Page, 100, 50, 50, WrapType.None);
shape.Rotation = 30.0;
builder.Writeln();
shape = builder.InsertShape(ShapeType.TextBox, 50, 50);
shape.Rotation = 30.0;
ステップ 4: ドキュメントを保存する
を使用してドキュメントを指定されたディレクトリに保存します。Save
方法。適切なファイル拡張子を付けて、目的のファイル名を指定します。この例では、ドキュメントを「WorkingWithShapes.InsertShape.docx」として保存します。
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(SaveFormat.Docx)
{
Compliance = OoxmlCompliance.Iso29500_2008_Transitional
};
doc.Save(dataDir + "WorkingWithShapes.InsertShape.docx", saveOptions);
Aspose.Words for .NET を使用した図形の挿入のソース コード例
//ドキュメントディレクトリへのパス
string dataDir = "YOUR DOCUMENT DIRECTORY";
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.InsertShape(ShapeType.TextBox, RelativeHorizontalPosition.Page, 100,
RelativeVerticalPosition.Page, 100, 50, 50, WrapType.None);
shape.Rotation = 30.0;
builder.Writeln();
shape = builder.InsertShape(ShapeType.TextBox, 50, 50);
shape.Rotation = 30.0;
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(SaveFormat.Docx)
{
Compliance = OoxmlCompliance.Iso29500_2008_Transitional
};
doc.Save(dataDir + "WorkingWithShapes.InsertShape.docx", saveOptions);
それでおしまい! Aspose.Words for .NET を使用して Word 文書に図形を正常に挿入しました。