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,48 @@
# Copyright (c) 2011-2023, Manfred Moitzi
# License: MIT License
from __future__ import annotations
from typing import TYPE_CHECKING, Optional
from ezdxf.lldxf.types import is_valid_handle
if TYPE_CHECKING:
from ezdxf.document import Drawing
START_HANDLE = "1"
class HandleGenerator:
def __init__(self, start_value: str = START_HANDLE):
self._handle: int = max(1, int(start_value, 16))
reset = __init__
def __str__(self):
return "%X" % self._handle
def next(self) -> str:
next_handle = self.__str__()
self._handle += 1
return next_handle
__next__ = next
def copy(self) -> HandleGenerator:
return HandleGenerator(str(self))
class UnderlayKeyGenerator(HandleGenerator):
def __str__(self):
return "Underlay%05d" % self._handle
def safe_handle(handle: Optional[str], doc: Optional["Drawing"] = None) -> str:
if handle is None:
return "0"
assert isinstance(handle, str), "invalid type"
if doc is not None:
if handle not in doc.entitydb:
return "0"
return handle
if not is_valid_handle(handle):
return "0"
return handle.upper()