在 Python 中创建 XBRL 文件
在 C# 中创建 XBRL 实例
Aspose.Finance支持创建XBRL文档。为此,API 提供了 XbrlDocument 类。 XbrlDocument 类的默认构造函数可用于创建新的 XBRL 实例文档。
以下代码片段演示了如何创建一个新的 XBRL 实例文档。
xbrlDoc = XbrlDocument() | |
xbrlInstances = xbrlDoc.xbrl_instances | |
xbrlInstance = xbrlInstances[xbrlInstances.add()] | |
xbrlDoc.save(os.path.join(outputDir, "dochavingItem.xbrl")) |
添加架构引用
Aspose.Finance 允许您在新创建的 XBRL 实例中添加模式引用。为此,API 提供了 SchemaRefCollection 类。
以下代码片段演示了将架构引用添加到新创建的 XBRL 实例。
xbrlDoc = XbrlDocument() | |
xbrlInstances = xbrlDoc.xbrl_instances | |
xbrlInstance = xbrlInstances[xbrlInstances.add()] | |
schemaRefs = xbrlInstance.schema_refs | |
schemaRefs.add(os.path.join(sourceDir, "schema.xsd"), "example", "http://example.com/xbrl/taxonomy") | |
xbrlDoc.save(os.path.join(outputDir, "dochavingItem.xbrl")) |
添加上下文
Aspose.Finance 允许您在新创建的 XBRL 实例中添加上下文。为此,API 提供了 Context 类。
以下代码片段演示了在新创建的 XBRL 实例中添加上下文。
xbrlDoc = XbrlDocument() | |
xbrlInstances = xbrlDoc.xbrl_instances | |
xbrlInstance = xbrlInstances[xbrlInstances.add()] | |
contextPeriod = ContextPeriod(datetime(2020,1,1), datetime(2020,2,10)) | |
contextEntity = ContextEntity("exampleIdentifierScheme", "exampleIdentifier") | |
context = Context(contextPeriod, contextEntity) | |
xbrlInstance.contexts.append(context) | |
xbrlDoc.save(os.path.join(outputDir, "dochavingItem.xbrl")) |
添加单位
Aspose.Finance 允许您在新创建的 XBRL 实例中添加上下文。为此,API 提供了 Unit 类。
以下代码片段演示了如何在新创建的 XBRL 实例中添加一个单元。
xbrlDoc = XbrlDocument() | |
xbrlInstances = xbrlDoc.xbrl_instances | |
xbrlInstance = xbrlInstances[xbrlInstances.add()] | |
unit = Unit(UnitType.MEASURE) | |
unit.measure_qualified_names.append(QualifiedName("USD", "iso4217", "http://www.xbrl.org/2003/iso4217")) | |
xbrlInstance.units.append(unit) | |
xbrlDoc.save(os.path.join(outputDir, "dochavingItem.xbrl")) |
添加项目
Aspose.Finance 允许您在新创建的 XBRL 实例中添加项目。为此,API 提供了 Item 类。
以下代码片段演示了如何在新创建的 XBRL 实例中添加项目。
xbrlDoc = XbrlDocument() | |
xbrlInstances = xbrlDoc.xbrl_instances | |
xbrlInstance = xbrlInstances[xbrlInstances.add()] | |
schemaRefs = xbrlInstance.schema_refs | |
schemaRefs.add(os.path.join(sourceDir, "schema.xsd"), "example", "http://example.com/xbrl/taxonomy") | |
schema = schemaRefs[0] | |
contextPeriod = ContextPeriod(datetime(2020,1,1), datetime(2020,2,10)) | |
contextEntity = ContextEntity("exampleIdentifierScheme", "exampleIdentifier") | |
context = Context(contextPeriod, contextEntity) | |
xbrlInstance.contexts.append(context) | |
unit = Unit(UnitType.MEASURE) | |
unit.measure_qualified_names.append(QualifiedName("USD", "iso4217", "http://www.xbrl.org/2003/iso4217")) | |
xbrlInstance.units.append(unit) | |
fixedAssetsConcept = schema.get_concept_by_name("fixedAssets") | |
if fixedAssetsConcept is not None: | |
item = Item(fixedAssetsConcept) | |
item.context_ref = context | |
item.unit_ref = unit | |
item.precision = 4 | |
item.value = "1444" | |
xbrlInstance.facts.append(item) | |
xbrlDoc.save(os.path.join(outputDir, "dochavingItem.xbrl")) |
添加脚注链接
Aspose.Finance 允许您在新创建的 XBRL 实例中添加脚注链接。为此,API 提供了 FootnoteLink 类。
以下代码片段演示了如何在新创建的 XBRL 实例中添加脚注链接。
xbrlDoc = XbrlDocument() | |
xbrlInstances = xbrlDoc.xbrl_instances | |
xbrlInstance = xbrlInstances[xbrlInstances.add()] | |
schemaRefs = xbrlInstance.schema_refs | |
schemaRefs.add(os.path.join(sourceDir, "schema.xsd"), "example", "http://example.com/xbrl/taxonomy") | |
schema = schemaRefs[0] | |
contextPeriod = ContextPeriod(datetime(2020,1,1), datetime(2020,2,10)) | |
contextEntity = ContextEntity("exampleIdentifierScheme", "exampleIdentifier") | |
context = Context(contextPeriod, contextEntity) | |
xbrlInstance.contexts.append(context) | |
footnoteLink = FootnoteLink() | |
footnote = Footnote("footnote1") | |
footnote.text = "Including the effects of the merger." | |
loc = Loc("#cd1", "fact1") | |
footnoteArc = FootnoteArc(loc.label, footnote.label) | |
footnoteLink.footnotes.append(footnote) | |
footnoteLink.locators.append(loc) | |
footnoteLink.footnote_arcs.append(footnoteArc) | |
xbrlInstance.footnote_links.append(footnoteLink) | |
xbrlDoc.save(os.path.join(outputDir, "xbrl_sample_with_footnotelink.xbrl")) |
添加角色参考
Aspose.Finance 允许您在新创建的 XBRL 实例中添加角色引用。为此,API 提供了 RoleReference 类。
以下代码片段演示了如何在新创建的 XBRL 实例中添加角色引用。
xbrlDoc = XbrlDocument() | |
xbrlInstances = xbrlDoc.xbrl_instances | |
xbrlInstance = xbrlInstances[xbrlInstances.add()] | |
schemaRefs = xbrlInstance.schema_refs | |
schemaRefs.add(os.path.join(sourceDir, "schema.xsd"), "example", "http://example.com/xbrl/taxonomy") | |
schema = schemaRefs[0] | |
roleType = schema.get_role_type_by_uri("http://abc.com/role/link1") | |
if roleType is not None: | |
roleReference = RoleReference(roleType) | |
xbrlInstance.role_references.append(roleReference) | |
xbrlDoc.save(os.path.join(outputDir, "xbrl_sample_with_roletype.xbrl")) |
添加圆弧角色参考
Aspose.Finance 允许您在新创建的 XBRL 实例中添加弧角色引用。为此,API 提供了 ArcroleReference 类。
以下代码片段演示了如何在新创建的 XBRL 实例中添加 arc 角色引用。
xbrlDoc = XbrlDocument() | |
xbrlInstances = xbrlDoc.xbrl_instances | |
xbrlInstance = xbrlInstances[xbrlInstances.add()] | |
schemaRefs = xbrlInstance.schema_refs | |
schemaRefs.add(os.path.join(sourceDir, "schema.xsd"), "example", "http://example.com/xbrl/taxonomy") | |
schema = schemaRefs[0] | |
arcroleType = schema.get_arcrole_type_by_uri("http://abc.com/arcrole/footnote-test") | |
if arcroleType is not None: | |
arcroleReference = ArcroleReference(arcroleType) | |
xbrlInstance.arcrole_references.append(arcroleReference) | |
xbrlDoc.save(os.path.join(outputDir, "xbrl_sample_with_arcroletype.xbrl")) |