Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Aspose.Words for Python via .NET は Aspose.Words for .NET のラッパーであるため、2 つの製品はほぼ同じ機能セットを備えています。ただし、このページで説明する作業には若干のニュアンスがあり、機能と API には違いがあります。
ラッピングプロセスにより、Python バージョンでは利用できない機能がいくつかあります。以下は、Python バージョンでは現在利用できない最も注目すべき機能のリストです。
Python 開発者にとって型キャストは自然ではありませんが、ドキュメント ノードまたはフィールドを具象型にキャストしないとタスクによっては実行できないものもあります。 Aspose.Words for Python via .NET は、必要な場合にオブジェクトをキャストできる特別なメソッドを提供します。
Aspose.Words DOM のすべてのドキュメント ノードの基本クラスは Node クラスです。たとえば、get_child メソッドは Node クラスのインスタンスを返しますが、返されたノードを変更する必要がある場合は、ほとんどの場合、それを具象型にキャストする必要があります。次のコードは、ドキュメント内の最初の Run のフォントの色を変更する方法を示しています。
doc = aw.Document(docs_base.my_dir + "Document.docx")
# Get the first Run node and cast it to Run object.
run = doc.get_child(aw.NodeType.RUN, 0, True).as_run()
# Make changes to the run
run.font.color = drawing.Color.red
# Save the result
doc.save(docs_base.artifacts_dir + "WorkingWithNode.change_run_color.docx")clone メソッドを使用する場合は、キャストも必要になる場合があります。
doc = aw.Document(docs_base.my_dir + "Document.docx")
clone = doc.clone().as_document()
clone.save(docs_base.artifacts_dir + "CloneAndCombineDocuments.cloning_document.docx")お気づきかと思いますが、C# コードではキャストに (Paragraph)node を使用しますが、Python では node.as_paragraph() メソッドを使用する必要があります。 Python バージョンの Aspose.Words Node クラスでは、次の as_xxx メソッドのリンクが導入されています。
ノードを指定されたタイプに分類できない場合、as_xxx メソッドは次のようなメッセージを含む RuntimeError を生成します。
RuntimeError: Proxy error(InvalidCastException): Unable to cast object of type ‘Aspose.Words.XXX’ to type ‘Aspose.Words.Drawing.YYY’.
同じ状況がフィールドにも当てはまります。次のコード例は、ハイパーリンクのリンクを置き換える方法を示しています。
doc = aw.Document(docs_base.my_dir + "Hyperlinks.docx")
for field in doc.range.fields :
if field.type == aw.fields.FieldType.FIELD_HYPERLINK:
hyperlink = field.as_field_hyperlink()
# Some hyperlinks can be local (links to bookmarks inside the document), ignore these.
if hyperlink.sub_address != None :
continue
hyperlink.address = "https:#www.aspose.com"
hyperlink.result = "Aspose - The .net & Java Component Publisher"
doc.save(docs_base.artifacts_dir + "WorkingWithFields.replace_hyperlinks.docx")お気づきかと思いますが、Field オブジェクトは、以下に示す as_xxx メソッドのセットも提供します。
テーブル スタイルを操作するにはキャストも必要です。
doc = aw.Document()
builder = aw.DocumentBuilder(doc)
table = builder.start_table()
builder.insert_cell()
builder.write("Name")
builder.insert_cell()
builder.write("Value")
builder.end_row()
builder.insert_cell()
builder.insert_cell()
builder.end_table()
# Add a table style and modify it's properties.
tableStyle = doc.styles.add(aw.StyleType.TABLE, "MyTableStyle1").as_table_style()
tableStyle.borders.line_style = aw.LineStyle.DOUBLE
tableStyle.borders.line_width = 1
tableStyle.left_padding = 18
tableStyle.right_padding = 18
tableStyle.top_padding = 12
tableStyle.bottom_padding = 12
table.style = tableStyle
doc.save(docs_base.artifacts_dir + "WorkingWithTableStylesAndFormatting.create_table_style.docx")次のコード例は、ActiveX コントロールのプロパティを読み取る方法を示しています。
doc = aw.Document(docs_base.my_dir + "ActiveX controls.docx")
properties = ""
for shape in doc.get_child_nodes(aw.NodeType.SHAPE, True) :
shape = shape.as_shape()
if shape.ole_format == None :
break
oleControl = shape.ole_format.ole_control
if oleControl.is_forms2_ole_control :
checkBox = oleControl.as_forms2_ole_control()
properties = properties + "\nCaption: " + checkBox.caption
properties = properties + "\nValue: " + checkBox.value
properties = properties + "\nEnabled: " + str(checkBox.enabled)
properties = properties + "\nType: " + str(checkBox.type)
if checkBox.child_nodes != None :
properties = properties + "\nChildNodes: " + checkBox.child_nodes
properties += "\n"
properties = properties + "\nTotal ActiveX Controls found: " + str(doc.get_child_nodes(aw.NodeType.SHAPE, True).count)
print("\n" + properties)FontSourceBase クラスは、以下に示す一連の as_xxx メソッドを提供します。
Aspose.Words for Python では、int タイプによるインデクサー プロパティのみが許可されますが、.NET では、文字列などの他のタイプを使用することができます。このギャップを埋めるために、次のクラスには追加のメソッドがあります。
Python の世界に近づけるため、Python via .NET の Aspose.Words の API メンバーは Python のスネーク スタイルを使用しますが、ほとんどの場合、.NET API の Aspose.Words に 1 対 1 の類似点があります。これらの類似物は XMLファイル にあります。
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.