Uahh/ToastFish · error
导入失败,Excel格式不正确或Excel文件损坏
Error message
导入失败,Excel格式不正确或Excel文件损坏
What it means
After parsing the workbook, ImportExcel branches on the value of the first cell of the first row; it only recognizes 英语, 日语, and 自定义. If the header cell is anything else, it shows '导入失败,Excel格式不正确或Excel文件损坏' and returns null. This is a template/contract check: the app expects one of three exact marker words in A1.
Solutions
- Open the workbook and set cell A1 of the first sheet to exactly 英语, 日语, or 自定义 (no spaces)
- Use the app's original template file as the base instead of a hand-made spreadsheet
- If you control the code, trim the header value before comparing: FirstRow.GetCell(0)?.ToString()?.Trim()
- Check for a null/empty first row — an empty sheet also lands in this branch
Example fix
// before
else
{
MessageBox.Show("导入失败,Excel格式不正确或Excel文件损坏");
return null;
}
// after
else
{
string header = FirstRow?.GetCell(0)?.ToString()?.Trim();
MessageBox.Show($"导入失败:表头应为 英语/日语/自定义,实际为 '{header}'");
return null;
} Defensive patterns
Strategy: validation
Validate before calling
using var fs = File.OpenRead(path);
var wb = new ExcelReader(); // or open with NPOI in a probe
string header = GetFirstSheetA1(path)?.Trim();
if (header != "英语" && header != "日语" && header != "自定义")
MessageBox.Show($"表头 {header} 不受支持,请使用官方模板"); Type guard
static bool IsValidTemplateHeader(object firstCell) =>
firstCell is string s && new[]{"英语","日语","自定义"}.Contains(s.Trim()); Try / catch
var result = Log.ImportExcel(path);
if (result == null) { MessageBox.Show("导入失败,Excel格式不正确或Excel文件损坏"); return; } Prevention
- Never rename or delete the A1 header cell in the import template
- Always start from the app's official template file
- Trim header text and avoid stray spaces/full-width characters
- Add the actual header value to the error message to speed diagnosis
When it happens
Trigger: ImportExcel reads a syntactically valid xlsx/xls whose A1 cell is not exactly 英语/日语/自定义 (extra whitespace, English headers like 'Word', empty A1, header on a different row, extra blank leading column).
Common situations: Users editing the provided import template and renaming/erasing the header; exporting word lists from other tools with different column layouts; localization differences or full-width vs half-width characters in the header cell.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- ex.Message, "Excel read error"
- 导入文件出错!
- ex.Message
- 程序已经在运行了,不能运行两次。\n如果右下角软件已经退出,请在任务管理器中结束ToastFish任务。
- 卡题出错!
AI-assisted analysis of Uahh/ToastFish@2508784a66 (2026-09-15).
Data as JSON: /api/errors/e3ce8cec0333d5d2.
Report an issue: GitHub.
Appendix: source
Thrown at Model/Log/CreateLog.cs:195
int RowCount = Sheet.LastRowNum;
int CellCount = FirstRow.LastCellNum;
for (int i = 1; i < RowCount; i++)
{
IRow Row = Sheet.GetRow(i);
CustomizeWord TempWord = new CustomizeWord();
if (Row == null)
continue;
TempWord.firstLine = Row.GetCell(1).ToString();
TempWord.secondLine = Row.GetCell(2).ToString();
TempWord.thirdLine = Row.GetCell(3).ToString();
TempWord.fourthLine = Row.GetCell(4).ToString();
CustWordList.Add(TempWord);
}
return CustWordList;
}
else
{
MessageBox.Show("导入失败,Excel格式不正确或Excel文件损坏");
return null;
}
}
}
}
View on GitHub (pinned to 2508784a66)