Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

首列偏移 #591

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,11 @@ public class ExcelImporterAttribute : ImporterAttribute
/// 是否仅导出错误数据
/// </summary>
public bool IsOnlyErrorRows { get; set; }


/// <summary>
/// 首列偏移量(默认为0,数据从第2列开始则偏移量为1)
/// </summary>
public int FirstColumnOffset { get; set; } = 0;
}
}
10 changes: 5 additions & 5 deletions src/Magicodes.ExporterAndImporter.Excel/Utility/ImportHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,8 @@ protected virtual void ParseTemplate(ExcelPackage excelPackage, ImportResultEnum
{
ExcelImporterSettings.HeaderRowIndex++;
}

for (var columnIndex = 1; columnIndex <= endColumnCount; columnIndex++)
var firstColumnOffset = ExcelImporterSettings.FirstColumnOffset;
for (var columnIndex = firstColumnOffset + 1; columnIndex <= endColumnCount; columnIndex++)
{
var header = worksheet.Cells[ExcelImporterSettings.HeaderRowIndex, columnIndex].Text;

Expand Down Expand Up @@ -659,7 +659,7 @@ protected virtual void ParseTemplate(ExcelPackage excelPackage, ImportResultEnum
});
throw new Exception($"{Resource.AnUnknownErrorOccurredInTheTemplate}{ex.Message}", ex);
}

}


Expand Down Expand Up @@ -1149,13 +1149,13 @@ protected virtual void ParseData(ExcelPackage excelPackage)

ImportResult.Data = new List<T>();
var propertyInfos = new List<PropertyInfo>(typeof(T).GetProperties());

var firstColumnOffset = ExcelImporterSettings.FirstColumnOffset;
for (var rowIndex = ExcelImporterSettings.HeaderRowIndex + 1;
rowIndex <= worksheet.Dimension.End.Row;
rowIndex++)
{
//跳过空行
if (worksheet.Cells[rowIndex, 1, rowIndex, worksheet.Dimension.End.Column].All(p => p.Text == string.Empty))
if (worksheet.Cells[rowIndex, 1 + firstColumnOffset, rowIndex, worksheet.Dimension.End.Column].All(p => p.Text == string.Empty))
{
EmptyRows.Add(rowIndex);
continue;
Expand Down
Loading