fix: stop excel fallback to openclaw and harden workbook save

This commit is contained in:
Mayorz 2026-03-04 16:20:10 +08:00
parent bfe3f168a2
commit 20d45b5f1d
2 changed files with 42 additions and 14 deletions

View File

@ -2318,8 +2318,8 @@ class OpenClawDingTalkBot(ChatbotHandler):
stderr_text = (proc.stderr or "").strip() stderr_text = (proc.stderr or "").strip()
if proc.returncode != 0 or not os.path.exists(output_path): if proc.returncode != 0 or not os.path.exists(output_path):
detail = stderr_text or stdout_text or "未知错误" detail = stderr_text or stdout_text or "未知错误"
self.logger.error("excel converter failed code=%s detail=%s", proc.returncode, detail[:800]) self.logger.error("excel converter failed code=%s detail=%s", proc.returncode, detail[:2500])
return f"Excel 转换失败:{detail[:500]}", False return f"Excel 转换失败:{detail[:1200]}", False
summary_line = "" summary_line = ""
for line in stdout_text.splitlines(): for line in stdout_text.splitlines():
@ -2584,6 +2584,7 @@ class OpenClawDingTalkBot(ChatbotHandler):
context_text = image_context_result.get("context_text", "") context_text = image_context_result.get("context_text", "")
if context_text: if context_text:
prompt_for_exec = self._merge_prompt_with_image_context(prompt, context_text) prompt_for_exec = self._merge_prompt_with_image_context(prompt, context_text)
if not has_excel_file:
if self._is_install_media_prompt(prompt): if self._is_install_media_prompt(prompt):
answer = await asyncio.to_thread(self._run_install_media_lookup, prompt) answer = await asyncio.to_thread(self._run_install_media_lookup, prompt)
elif self._is_dalongxia_analytics_prompt(prompt): elif self._is_dalongxia_analytics_prompt(prompt):

View File

@ -307,6 +307,26 @@ def process_sheet(sheet, args: argparse.Namespace, ssl_context, temp_files: list
return results return results
def drop_broken_images(workbook) -> int:
removed = 0
for sheet in workbook.worksheets:
existing = list(getattr(sheet, "_images", []))
if not existing:
continue
kept = []
removed_in_sheet = 0
for image in existing:
try:
image._data()
kept.append(image)
except Exception:
removed += 1
removed_in_sheet += 1
if removed_in_sheet:
sheet._images = kept
return removed
def main() -> int: def main() -> int:
args = parse_args() args = parse_args()
@ -333,6 +353,13 @@ def main() -> int:
output_path.parent.mkdir(parents=True, exist_ok=True) output_path.parent.mkdir(parents=True, exist_ok=True)
try: try:
try:
workbook.save(output_path)
except Exception as save_error:
removed = drop_broken_images(workbook)
if removed <= 0:
raise
print(f"WARN: dropped_broken_images={removed} reason={save_error}")
workbook.save(output_path) workbook.save(output_path)
finally: finally:
for file_path in temp_files: for file_path in temp_files: