Improve chips virgens table detection
This commit is contained in:
parent
900954e992
commit
4396733263
|
|
@ -1360,6 +1360,10 @@ namespace line_gestao_api.Controllers
|
|||
for (int i = 0; i < headers.Count; i++)
|
||||
{
|
||||
var headerRow = headers[i];
|
||||
var lastCol = headerRow.LastCellUsed()?.Address.ColumnNumber
|
||||
?? ws.LastColumnUsed()?.ColumnNumber()
|
||||
?? headerRow.LastCellUsed()?.Address.ColumnNumber
|
||||
?? 1;
|
||||
var itemColumns = headerRow.CellsUsed()
|
||||
.Where(c => NormalizeHeader(c.GetString()) == "ITEM")
|
||||
.Select(c => c.Address.ColumnNumber)
|
||||
|
|
@ -1375,12 +1379,11 @@ namespace line_gestao_api.Controllers
|
|||
var startCol = itemColumns[tableIndex];
|
||||
var endCol = tableIndex + 1 < itemColumns.Count
|
||||
? itemColumns[tableIndex + 1] - 1
|
||||
: headerRow.LastCellUsed()?.Address.ColumnNumber ?? startCol;
|
||||
: lastCol;
|
||||
|
||||
var map = BuildHeaderMapRange(headerRow, startCol, endCol);
|
||||
int colItem = GetCol(map, "ITEM");
|
||||
int colChip = GetColAny(map, "Nº DO CHIP", "N° DO CHIP", "NUMERO DO CHIP", "N DO CHIP", "NUM. DO CHIP", "CHIP");
|
||||
int colObs = GetColAny(map, "OBSERVAÇÕES", "OBSERVACOES", "OBSERVACAO", "OBS");
|
||||
int colItem = startCol;
|
||||
int colChip = FindHeaderColumn(headerRow, startCol, endCol, "CHIP");
|
||||
int colObs = FindHeaderColumn(headerRow, startCol, endCol, "OBS");
|
||||
if (colItem == 0 || colChip == 0 || colObs == 0) continue;
|
||||
|
||||
for (int r = startRow; r <= endRow; r++)
|
||||
|
|
@ -1670,6 +1673,28 @@ namespace line_gestao_api.Controllers
|
|||
return map;
|
||||
}
|
||||
|
||||
private static int FindHeaderColumn(IXLRow headerRow, int startCol, int endCol, params string[] headerKeys)
|
||||
{
|
||||
var normalizedKeys = headerKeys.Select(NormalizeHeader).Where(k => !string.IsNullOrWhiteSpace(k)).ToArray();
|
||||
if (normalizedKeys.Length == 0) return 0;
|
||||
|
||||
for (int col = startCol; col <= endCol; col++)
|
||||
{
|
||||
var key = NormalizeHeader(headerRow.Cell(col).GetString());
|
||||
if (string.IsNullOrWhiteSpace(key)) continue;
|
||||
|
||||
foreach (var wanted in normalizedKeys)
|
||||
{
|
||||
if (key == wanted || key.Contains(wanted))
|
||||
{
|
||||
return col;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static DateTime? ToUtc(DateTime? dt)
|
||||
{
|
||||
if (dt == null) return null;
|
||||
|
|
|
|||
Loading…
Reference in New Issue