INNER CODE UNIT · Python
_cell
wzyn20051216/solidworks-automation-skill · apps/desktop/cad_workbench/app.py:489
def _cell(self, table: QTableWidget, row: int, column: int) -> str:
item = table.item(row, column)
return item.text().strip() if item else ""
def _float_cell(self, table: QTableWidget, row: int, column: int) -> float:
text = self._cell(table, row, column)
try:
return float(text) if text else 0.0
except ValueError as exc:
header = table.horizontalHeaderItem(column).text()
raise ValueError(f"第 {row + 1} 行「{header}」必须是数字") from exc
def _int_cell(self, table: QTableWidget, row: int, column: int) -> int:
text = self._cell(table, row, column)
try:
return int(float(text)) if text else 0
except ValueError as exc:
header = table.horizontalHeaderItem(column).text()