{"record":{"id":"e3ce8cec0333d5d2","repo":"Uahh/ToastFish","slug":"excel-excel","errorCode":null,"errorMessage":"导入失败，Excel格式不正确或Excel文件损坏","messagePattern":"导入失败，Excel格式不正确或Excel文件损坏","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"Model/Log/CreateLog.cs","lineNumber":195,"sourceCode":"                int RowCount = Sheet.LastRowNum;\n                int CellCount = FirstRow.LastCellNum;\n                for (int i = 1; i < RowCount; i++)\n                {\n                    IRow Row = Sheet.GetRow(i);\n                    CustomizeWord TempWord = new CustomizeWord();\n                    if (Row == null)\n                        continue;\n                    TempWord.firstLine = Row.GetCell(1).ToString();\n                    TempWord.secondLine = Row.GetCell(2).ToString();\n                    TempWord.thirdLine = Row.GetCell(3).ToString();\n                    TempWord.fourthLine = Row.GetCell(4).ToString();\n                    CustWordList.Add(TempWord);\n                }\n                return CustWordList;\n            }\n            else\n            {\n                MessageBox.Show(\"导入失败，Excel格式不正确或Excel文件损坏\");\n                return null;\n            }\n        }\n    }\n}\n","sourceCodeStart":177,"sourceCodeEnd":201,"githubUrl":"https://github.com/Uahh/ToastFish/blob/2508784a6650862a60e1f3ec3a54dd83efdec98b/Model/Log/CreateLog.cs#L177-L201","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nelse\n{\n    MessageBox.Show(\"导入失败，Excel格式不正确或Excel文件损坏\");\n    return null;\n}\n// after\nelse\n{\n    string header = FirstRow?.GetCell(0)?.ToString()?.Trim();\n    MessageBox.Show($\"导入失败：表头应为 英语/日语/自定义，实际为 '{header}'\");\n    return null;\n}","handlingStrategy":"validation","validationCode":"using var fs = File.OpenRead(path);\nvar wb = new ExcelReader(); // or open with NPOI in a probe\nstring header = GetFirstSheetA1(path)?.Trim();\nif (header != \"英语\" && header != \"日语\" && header != \"自定义\")\n    MessageBox.Show($\"表头 {header} 不受支持，请使用官方模板\");","typeGuard":"static bool IsValidTemplateHeader(object firstCell) =>\n    firstCell is string s && new[]{\"英语\",\"日语\",\"自定义\"}.Contains(s.Trim());","tryCatchPattern":"var result = Log.ImportExcel(path);\nif (result == null) { MessageBox.Show(\"导入失败，Excel格式不正确或Excel文件损坏\"); return; }","preventionTips":["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"],"tags":["csharp","excel","template","import","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"2508784a6650862a60e1f3ec3a54dd83efdec98b","analyzedAt":"2026-09-15T23:21:32.897Z","contentChangedAt":"2026-09-15T23:21:32.897Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}