Cómo inspeccionar etiquetas de OneNote en Python

Cómo inspeccionar etiquetas de OneNote en Python

OneNote permite a los usuarios anotar contenido con etiquetas de colores: estrellas, casillas de verificación, banderas importantes y etiquetas personalizadas. Aspose.Note FOSS for Python expone estas anotaciones como objetos NoteTag en los nodos RichText, Image, AttachedFile y Table a través de su propiedad .Tags. Esta guía muestra cómo leerlas.


Guía paso a paso

Paso 1: Instalar Aspose.Note FOSS para Python

pip install aspose-note

Paso 2: Cargar el archivo .one

from aspose.note import Document

doc = Document("TaggedNotes.one")
print(f"Pages: {len(list(doc))}")

Paso 3: Encontrar etiquetas en nodos RichText

La mayoría de las etiquetas están adjuntas a bloques de texto:

from aspose.note import Document, RichText

doc = Document("TaggedNotes.one")
for rt in doc.GetChildNodes(RichText):
    for tag in rt.Tags:
        print(f"[RichText] Label={tag.Label!r}  Icon={tag.Icon}  text={rt.Text.strip()!r}")

Paso 4: Encontrar etiquetas en imágenes

from aspose.note import Document, Image

doc = Document("TaggedNotes.one")
for img in doc.GetChildNodes(Image):
    for tag in img.Tags:
        print(f"[Image] Label={tag.Label!r}  filename={img.FileName!r}")

Paso 5: Encontrar etiquetas en tablas

from aspose.note import Document, Table

doc = Document("TaggedNotes.one")
for table in doc.GetChildNodes(Table):
    for tag in table.Tags:
        print(f"[Table] Label={tag.Label!r}  widths={[col.Width for col in table.Columns]}")

Paso 6: Recopilar todas las etiquetas en todo el documento

from aspose.note import Document, RichText, Image, Table

doc = Document("TaggedNotes.one")
all_tags = []

for rt in doc.GetChildNodes(RichText):
    for tag in rt.Tags:
        all_tags.append({"type": "RichText", "Label": tag.Label,
                         "CompletedTime": tag.CompletedTime, "text": rt.Text.strip()})
for img in doc.GetChildNodes(Image):
    for tag in img.Tags:
        all_tags.append({"type": "Image", "Label": tag.Label,
                         "CompletedTime": tag.CompletedTime, "file": img.FileName})
for table in doc.GetChildNodes(Table):
    for tag in table.Tags:
        all_tags.append({"type": "Table", "Label": tag.Label,
                         "CompletedTime": tag.CompletedTime})

print(f"Total tagged items: {len(all_tags)}")
for item in all_tags:
    print(item)

Referencia de la propiedad NoteTag

PropiedadTipoDescripción
Iconint | NoneIdentificador numérico de forma de etiqueta (estrella, casilla de verificación, flecha, etc.)
Labelstr | NoneCadena de etiqueta legible por humanos (p. ej., "Important", "To Do")
FontColorint | NoneColor del texto como entero ARGB
Highlightint | NoneColor de resaltado como entero ARGB
CreationTimedatetime | NoneCuándo se creó la etiqueta
CompletedTimedatetime | NoneCuándo se completó la etiqueta (None si no está completada)
StatusTagStatusTagStatus.Completed si está completada, de lo contrario TagStatus.Open

Filtro Completado vs Etiquetas Pendientes

Las etiquetas que se han marcado (como casillas de verificación “To Do”) tienen un campo no-None CompletedTime:

from aspose.note import Document, RichText

doc = Document("TaggedNotes.one")
pending, done = [], []

for rt in doc.GetChildNodes(RichText):
    for tag in rt.Tags:
        item = {"Label": tag.Label, "text": rt.Text.strip()}
        if tag.CompletedTime is None:
            pending.append(item)
        else:
            done.append(item)

print(f"Pending: {len(pending)}  Done: {len(done)}")
for p in pending:
    print(f"  [ ] {p['Label']}: {p['text']!r}")
for d in done:
    print(f"  [x] {d['Label']}: {d['text']!r}")

Crear una NoteTag (En memoria)

El método de fábrica NoteTag.CreateYellowStar() crea un nodo de etiqueta que puedes adjuntar a nuevo contenido en memoria:

from aspose.note import NoteTag

tag = NoteTag.CreateYellowStar()
print(f"Created tag: Icon={tag.Icon}  Label={tag.Label!r}")

La creación en memoria es útil para la compatibilidad de la API. Dado que no se admite escribir de nuevo en .one, las etiquetas creadas no pueden persistirse en el archivo.


Problemas comunes

No se encontraron etiquetas (el documento devuelve listas de etiquetas vacías): No todos los archivos .one contienen etiquetas. Verifique que el documento fuente tenga etiquetas visibles en Microsoft OneNote antes de solucionar el código.

tag.Label es una cadena vacía: Algunas formas de etiqueta no tienen una etiqueta de texto en los metadatos del archivo. Use tag.Icon para identificar el tipo de etiqueta programáticamente.


Recursos relacionados:

 Español