diff --git a/src/Excel2TextDiff/Excel2TextWriter.cs b/src/Excel2TextDiff/Excel2TextWriter.cs index 1b096c1..2536c99 100644 --- a/src/Excel2TextDiff/Excel2TextWriter.cs +++ b/src/Excel2TextDiff/Excel2TextWriter.cs @@ -29,26 +29,24 @@ namespace Excel2TextDiff private void LoadRows(IExcelDataReader reader, List lines) { - int rowIndex = 0; + var row = new List(); while (reader.Read()) { - ++rowIndex; // 第一行是 meta ,跳过 - var row = new List(); + row.Clear(); for (int i = 0, n = reader.FieldCount; i < n; i++) { object cell = reader.GetValue(i); row.Add(cell != null ? cell.ToString() : ""); } + // 只保留到最后一个非空白单元格 int lastNotEmptyIndex = row.FindLastIndex(s => !string.IsNullOrEmpty(s)); if (lastNotEmptyIndex >= 0) { - row = row.GetRange(0, lastNotEmptyIndex + 1); - lines.Add(string.Join(',', row)); + lines.Add(string.Join(',', row.GetRange(0, lastNotEmptyIndex + 1))); } else { // 忽略空白行,没必要diff这个 - row.Clear(); } } }