Aspose.Note FOSS for Python
此参考文档覆盖了完整的公共 API 表面 aspose-note 版本 26.3.1。仅记录从 aspose.note 包中导出的符号在此处有文档。任何位于 aspose.note._internal 是实现细节,可能会在不另行通知的情况下更改。.
Properties: pip install aspose-note (core) 或 pip install "aspose-note[pdf]" (带 PDF 导出)
Properties: from aspose.note import Document, RichText, ...
Properties
文档与遍历
| Properties | Properties |
|---|---|
Document | 根文档对象。加载一个 .one 文件,遍历页面,并保存为 PDF。. |
DocumentVisitor | 文档树的访问者模式遍历的抽象基类。. |
Node | 所有文档节点的基类。. |
CompositeNode | 可包含子节点的节点的基类。. |
文档结构
| Properties | Properties |
|---|---|
Page | 表示一个 OneNote 页面。. |
Title | 页面标题块,包含 TitleText、TitleDate、TitleTime。. |
Outline | OutlineElement 节点的定位容器。. |
OutlineElement | 叶子容器;保存 RichText、Image、Table、AttachedFile。. |
Properties
| Properties | Properties |
|---|---|
RichText | 带有格式运行、标签和超链接的文本块。. |
TextRun | RichText 中的单个格式化文本段。. |
TextStyle | TextRun 的格式属性。. |
Image | 嵌入的图像,包含原始字节和元数据。. |
AttachedFile | 嵌入的文件附件,包含原始字节。. |
Table | 包含行、单元格和列宽的表格。. |
TableRow | 表格中的一行。. |
TableCell | TableRow 中的单元格;包含内容节点。. |
NoteTag | 附加在内容节点上的 OneNote 标签(星标、复选框等)。. |
NumberList | OutlineElement 上的编号列表元数据。. |
Properties
| Properties | Properties |
|---|---|
LoadOptions | 加载选项 .one 文件。. |
SaveOptions | 保存选项的基类。. |
PdfSaveOptions | PDF 特定的保存选项(标签图标)。. |
兼容性存根
| Properties | Properties |
|---|---|
License | 兼容性存根:: SetLicense() 在此 FOSS 实现中是一个空操作。. |
Metered | 兼容性存根:: SetMeteredKey() 在此 FOSS 实现中是一个空操作。. |
类详情
Properties
根文档类。加载一个 .one 文件,从文件路径, pathlib.Path,,或二进制流。.
from aspose.note import Document, LoadOptions
doc = Document(source=None, load_options=None)构造函数参数:
| Properties | Properties | Properties |
|---|---|---|
source | `str | Path |
load_options | `LoadOptions | None` |
Properties:
| Properties | Properties | Properties |
|---|---|---|
DisplayName | `str | None` |
CreationTime | `datetime | None` |
FileFormat | FileFormat | 尽力指示 OneNote 文件格式版本 |
Properties:
| Properties | Properties | Properties |
|---|---|---|
Count() | () -> int | 直接子页面数量 |
GetPageHistory(page) | (Page) -> list[Page] | Properties [page] (存根;完整历史尚未实现) |
DetectLayoutChanges() | () -> None | 兼容性存根;无操作 |
Save(target, format_or_options) | `(str | Path |
Accept(visitor) | (DocumentVisitor) -> None | 调用访问者遍历 |
for page in doc | N/A | 遍历直接子节点 Page 节点 |
Document.FileFormat 注意::该属性提供对 OneNote 文件格式版本的最佳努力指示。 FileFormat 枚举有三个值:: OneNote2010, OneNoteOnline,,以及 OneNote2007.
Document.Save() 流支持: target 可以是二进制流(io.BytesIO,,以二进制写入模式打开的文件句柄等)。这在测试套件中得到确认:: doc.Save(io.BytesIO(), PdfSaveOptions(SaveFormat.Pdf)).
DocumentVisitor
用于访问者模式遍历的抽象基类。覆盖您需要的 visit 方法::
| Properties | 在以下情况下调用 |
|---|---|
VisitDocumentStart(doc) | 进入 Document 节点 |
VisitDocumentEnd(doc) | 离开 Document 节点 |
VisitPageStart(page) | 进入 Page 节点 |
VisitPageEnd(page) | 离开 Page 节点 |
VisitTitleStart(title) | 进入 Title 节点 |
VisitTitleEnd(title) | 离开 Title 节点 |
VisitOutlineStart(outline) | 进入 Outline 节点 |
VisitOutlineEnd(outline) | 离开 Outline 节点 |
VisitOutlineElementStart(oe) | 进入 OutlineElement 节点 |
VisitOutlineElementEnd(oe) | 离开 OutlineElement 节点 |
VisitRichTextStart(rt) | 进入 RichText 节点 |
VisitRichTextEnd(rt) | 离开 RichText 节点 |
VisitImageStart(img) | 进入 Image 节点 |
VisitImageEnd(img) | 离开 Image 节点 |
Properties
所有文档树节点的基类。.
| 属性 / 方法 | Properties | Properties |
|---|---|---|
ParentNode | `Node | None` |
Document | `Document | None` |
Accept(visitor) | (DocumentVisitor) -> None | 为此节点分派访问者 |
CompositeNode
Properties Node. 添加子节点管理::
| 属性 / 方法 | Properties |
|---|---|
FirstChild | 第一个子节点,或 None |
LastChild | 最后一个子节点,或 None |
AppendChildLast(node) | 在末尾添加子节点;设置 node.ParentNode = self |
AppendChildFirst(node) | 在开头添加子节点 |
InsertChild(index, node) | 在给定位置插入子节点 |
RemoveChild(node) | 移除子节点;设置 node.ParentNode = None |
GetEnumerator() | 返回直接子节点的迭代器 |
for child in node | 遍历直接子节点 |
GetChildNodes(Type) | (Type) -> list[Type]::递归的深度优先搜索整个子树,包括 self |
Properties
Properties CompositeNode. 表示一个 OneNote 页面。.
| Properties | Properties | Properties |
|---|---|---|
Title | `Title | None` |
Author | `str | None` |
CreationTime | `datetime | None` |
LastModifiedTime | `datetime | None` |
Level | `int | None` |
Properties:
| Properties | Properties |
|---|---|
Clone(deep=False) | 返回页面的浅拷贝或深拷贝 |
Properties
Properties CompositeNode.。保存标题块的 Page.
| Properties | Properties | Properties |
|---|---|---|
TitleText | `RichText | None` |
TitleDate | `RichText | None` |
TitleTime | `RichText | None` |
Properties
Properties CompositeNode.。一个用于定位的容器 OutlineElement 节点。.
| Properties | Properties | Properties |
|---|---|---|
X | `float | None` |
Y | `float | None` |
Width | `float | None` |
OutlineElement
Properties CompositeNode.。一个保存内容节点的叶子容器。.
| Properties | Properties | Properties |
|---|---|---|
IndentLevel | int | 嵌套深度(0 = 最外层) |
NumberList | `NumberList | None` |
Tags | list[NoteTag] | 附加到此元素的 OneNote 标签 |
RichText
Properties CompositeNode.。一段样式化文本。.
| Properties | Properties | Properties |
|---|---|---|
Text | str | 完整的纯文本字符串(所有运行拼接) |
Runs | list[TextRun] | 已排序的格式化段落列表 |
FontSize | `float | None` |
Tags | list[NoteTag] | 附加到此块的 OneNote 标签 |
Properties:
| Properties | Properties | Properties |
|---|---|---|
Append(text, style=None) | `(str, TextStyle | None) -> RichText` |
Replace(old_value, new_value) | (str, str) -> None | 在内存中对…进行字符串替换 Text;;不更新 Runs |
TextRun
Properties Node.。单个格式化文本段。.
| Properties | Properties | Properties |
|---|---|---|
Text | str | 段的文本内容(默认 "") |
Style | TextStyle | 格式属性 |
Start | `int | None` |
End | `int | None` |
TextStyle
Properties Node.。针对…的每字符格式属性 TextRun.
| Properties | Properties | Properties | Properties |
|---|---|---|---|
Bold | bool | False | Properties |
Italic | bool | False | Properties |
Underline | bool | False | Properties |
Strikethrough | bool | False | Properties |
Superscript | bool | False | Properties |
Subscript | bool | False | Properties |
FontName | `str | None` | None |
FontSize | `float | None` | None |
FontColor | `int | None` | None |
HighlightColor | `int | None` | None |
LanguageId | `int | None` | None |
IsHyperlink | bool | False | 此运行是否为超链接 |
HyperlinkAddress | `str | None` | None |
Properties
Properties CompositeNode. 嵌入的图像。.
| Properties | Properties | Properties |
|---|---|---|
FileName | `str | None` |
Bytes | bytes | 原始图像数据(默认 b"") |
Width | `float | None` |
Height | `float | None` |
AlternativeTextTitle | `str | None` |
AlternativeTextDescription | `str | None` |
HyperlinkUrl | `str | None` |
Tags | list[NoteTag] | 附加在此图像上的 OneNote 标签 |
Properties:
| Properties | Properties |
|---|---|
Replace(image) | Properties Bytes 和 FileName 来自另一个 Image 节点到此节点 |
AttachedFile
Properties CompositeNode. 嵌入的文件附件。.
| Properties | Properties | Properties |
|---|---|---|
FileName | `str | None` |
Bytes | bytes | 原始文件数据(默认 b"") |
Tags | list[NoteTag] | 附加在此附件上的 OneNote 标签 |
Properties
Properties CompositeNode. OutlineElement 中的表格。.
| Properties | Properties | Properties | Properties |
|---|---|---|---|
Columns | list[float] | [] | 每列的宽度(单位:磅) |
IsBordersVisible | bool | True | 表格边框是否可见 |
Tags | list[NoteTag] | [] | 附加在此表格上的 OneNote 标签 |
TableRow
Properties CompositeNode. 在…中的一行 Table. 遍历 GetChildNodes(TableCell) 以访问单元格。.
TableCell
Properties CompositeNode. 位于…中的单元格 TableRow. 包含 RichText, Image, 以及其他内容节点。.
NoteTag
Properties Node. 一个附加到内容节点的 OneNote 标记。.
| Properties | Properties | Properties | Properties |
|---|---|---|---|
shape | `int | None` | None |
label | `str | None` | None |
text_color | `int | None` | None |
highlight_color | `int | None` | None |
created | `int | None` | None |
completed | `int | None` | None |
时间戳备注: created 和 completed 是从 MS-ONE 二进制格式解析出的原始整数时间戳,而不是 datetime 对象。.
工厂方法:
| Properties | Properties |
|---|---|
NoteTag.CreateYellowStar() | 创建一个 NoteTag(shape=None, label="Yellow Star") |
NumberList
Properties Node. 编号或项目符号列表的元数据在一个 OutlineElement.
| Properties | Properties | Properties | Properties |
|---|---|---|---|
Format | `str | None` | None |
Restart | `int | None` | None |
IsNumbered | bool | False | 有序(编号)列表为 true |
LoadOptions
| Properties | Properties | Properties | Properties |
|---|---|---|---|
DocumentPassword | `str | None` | None |
LoadHistory | bool | False | API 兼容性字段;在 v26.3.1 中未实际使用 |
SaveOptions
所有保存选项的基类。必需的位置参数。.
| Properties | Properties | Properties |
|---|---|---|
SaveFormat | SaveFormat | 目标保存格式 |
PdfSaveOptions
Properties SaveOptions. PDF 特定的导出配置。使用以下方式构建 PdfSaveOptions(SaveFormat.Pdf).
| Properties | Properties | Properties | Properties |
|---|---|---|---|
PageIndex | int | 0 | 字段存在;; 在 v26.3.1 中未转发给 PDF 导出器::对输出没有影响 |
PageCount | `int | None` | None |
TagIconDir | `str | None` | None |
TagIconSize | `float | None` | None |
TagIconGap | `float | None` | None |
PageIndex / PageCount 注意事项::这些字段在 PdfSaveOptions 为了 API 兼容性,但 Document.Save() v26.3.1 版的实现不会读取或转发它们到 PDF 导出器。所有页面始终都会被导出。.
许可证和计量
导出兼容性存根以实现与 Aspose.Note 对 .NET 的 API 形状兼容。在此 FOSS 实现中,所有方法均为空操作。.
from aspose.note import License, Metered
lic = License()
lic.SetLicense("path/to/license.lic") # no-op
m = Metered()
m.SetMeteredKey("public_key", "private_key") # no-op使用 Aspose.Note FOSS for Python 的任何功能均不需要许可证密钥。.
Properties
完整枚举参考:: Properties
SaveFormat
| Properties | Properties |
|---|---|
SaveFormat.Pdf | PDF 导出:已实现;需要 pip install "aspose-note[pdf]" |
SaveFormat.One | OneNote 格式:仅声明;会引发 UnsupportedSaveFormatException |
FileFormat
枚举值表示 OneNote 文件格式版本。. Document.FileFormat 提供尽力而为的指示。.
| Properties | 字符串值 |
|---|---|
FileFormat.OneNote2010 | "onenote2010" |
FileFormat.OneNoteOnline | "onenoteonline" |
FileFormat.OneNote2007 | "onenote2007" |
HorizontalAlignment
| Properties | 字符串值 |
|---|---|
HorizontalAlignment.Left | "left" |
HorizontalAlignment.Center | "center" |
HorizontalAlignment.Right | "right" |
NodeType
| Properties | 字符串值 |
|---|---|
NodeType.Document | "document" |
NodeType.Page | "page" |
NodeType.Outline | "outline" |
NodeType.OutlineElement | "outline_element" |
NodeType.RichText | "rich_text" |
NodeType.Image | "image" |
NodeType.Table | "table" |
NodeType.AttachedFile | "attached_file" |
Properties
完整异常参考:: Properties
| Properties | Properties |
|---|---|
AsposeNoteError | 所有 Aspose.Note FOSS 异常的基类 |
FileCorruptedException | Properties .one 文件无法解析(已损坏或二进制格式错误) |
IncorrectDocumentStructureException | 文件结构无效或不受支持 |
IncorrectPasswordException | 在以下情况下抛出 LoadOptions.DocumentPassword 已设置;不支持加密文档 |
UnsupportedFileFormatException | 文件格式未被识别;暴露了一个 FileFormat 字段(字符串) |
UnsupportedSaveFormatException | 请求的 SaveFormat 在此版本中未实现 |