Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Aspose.Words cho Python via .NET là trình bao bọc của Aspose.Words cho .NET, đó là lý do tại sao hai sản phẩm này có bộ tính năng gần như giống nhau. Tuy nhiên, có một số sắc thái trong công việc cũng như sự khác biệt về tính năng và API, được mô tả trên trang này.
Do quá trình gói nên có một số tính năng không có trong phiên bản Python. Dưới đây là danh sách các tính năng đáng chú ý nhất hiện chưa có trong phiên bản Python.
Mặc dù việc truyền kiểu không phải là điều tự nhiên đối với các nhà phát triển Python, một số tác vụ không thể hoàn thành nếu không truyền các nút hoặc trường tài liệu sang loại cụ thể. Aspose.Words cho Python via .NET cung cấp các phương thức đặc biệt cho phép truyền các đối tượng khi cần thiết.
Lớp cơ sở cho tất cả các nút tài liệu trong Aspose.Words DOM là lớp Node. Ví dụ, phương thức get_child trả về và thể hiện của lớp Node, nhưng nếu bạn cần sửa đổi nút được trả về, trong hầu hết các trường hợp, bạn nên chuyển nó thành kiểu cụ thể. Đoạn mã sau minh họa cách thay đổi màu phông chữ của Run đầu tiên trong tài liệu:
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")Việc truyền cũng có thể được yêu cầu khi sử dụng phương pháp 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")Như bạn có thể nhận thấy trong mã C# bạn sẽ sử dụng (Paragraph)node để truyền, trong Python bạn phải sử dụng phương thức node.as_paragraph(). Trong phiên bản Python của lớp Aspose.Words Node giới thiệu liên kết các phương thức as_xxx sau:
Phương thức as_xxx đưa ra một RuntimeError với thông báo như sau nếu nút không thể xếp vào loại đã chỉ định:
RuntimeError: Proxy error(InvalidCastException): Unable to cast object of type ‘Aspose.Words.XXX’ to type ‘Aspose.Words.Drawing.YYY’.
Tình huống tương tự cũng được áp dụng cho các lĩnh vực. Ví dụ mã sau đây minh họa cách thay thế các liên kết siêu liên kết:
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")Như bạn có thể nhận thấy, đối tượng Field cũng cung cấp tập hợp các phương thức as_xxx, được liệt kê bên dưới:
Việc truyền cũng được yêu cầu để làm việc với các kiểu bảng:
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")Ví dụ mã sau đây minh họa cách đọc thuộc tính điều khiển 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)Lớp FontSourceBase cung cấp tập hợp các phương thức as_xxx, được liệt kê bên dưới:
Aspose.Words cho Python chỉ cho phép các thuộc tính của trình lập chỉ mục theo loại int, trong .NET tuy nhiên có thể sử dụng các loại khác, ví dụ như chuỗi. Để lấp đầy khoảng trống này, các lớp sau có một phương thức bổ sung:
Để gần gũi hơn với thế giới Python, các thành viên API của Aspose.Words dành cho Python via .NET sử dụng kiểu rắn Pythonic, tuy nhiên trong hầu hết các trường hợp, chúng có kiểu tương tự 1-1 trong Aspose.Words cho .NET API. Bạn có thể tìm thấy những chất tương tự này trong tập tin xml.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.