refactor: excel parse

This commit is contained in:
Blizzard
2026-04-16 10:01:11 +08:00
parent 680ecc320f
commit f62f95ec02
7941 changed files with 2899112 additions and 0 deletions
@@ -0,0 +1,50 @@
# Copyright (c) 2011-2022, Manfred Moitzi
# License: MIT License
from __future__ import annotations
from typing import Sequence, TYPE_CHECKING, Iterable
from ezdxf.lldxf.tagger import internal_tag_compiler
if TYPE_CHECKING:
from ezdxf.lldxf.types import DXFTag
from ezdxf.lldxf.extendedtags import ExtendedTags
def compile_tags_without_handles(text: str) -> Iterable[DXFTag]:
return (
tag for tag in internal_tag_compiler(text) if tag.code not in (5, 105)
)
def normlines(text: str) -> Sequence[str]:
lines = text.split("\n")
return [line.strip() for line in lines]
def load_section(text: str, name: str) -> list[ExtendedTags]:
from ezdxf.lldxf.loader import load_dxf_structure
dxf = load_dxf_structure(
internal_tag_compiler(text), ignore_missing_eof=True
)
return dxf[name] # type: ignore
def load_entities(text: str, name: str):
from ezdxf.lldxf.loader import load_dxf_structure, load_dxf_entities
dxf = load_dxf_structure(
internal_tag_compiler(text), ignore_missing_eof=True
)
return load_dxf_entities(dxf[name]) # type: ignore
def parse_hex_dump(txt: str) -> bytes:
b = bytearray()
lines = txt.split("\n")
for line in lines:
if line == "":
continue
data = [int(v, 16) for v in line.strip().split(" ")]
assert data[0] == len(b)
b.extend(data[1:])
return b