From 1a8f2a523118734bdb468b11ee6bd745ff3ac8bc Mon Sep 17 00:00:00 2001 From: walon Date: Tue, 6 Jul 2021 11:52:33 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BC=98=E5=8C=96=E3=80=91=E7=95=A5?= =?UTF-8?q?=E5=BE=AE=E4=BC=98=E5=8C=96=E4=BA=86Excel2TextDiff=E8=AF=BB?= =?UTF-8?q?=E5=8F=96excel=E7=9A=84=E6=80=A7=E8=83=BD=EF=BC=8C=E5=90=8C?= =?UTF-8?q?=E6=97=B6=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Excel2TextDiff/Excel2TextWriter.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) 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(); } } }