--carga excel

This commit is contained in:
2022-02-22 06:53:00 -07:00
parent 25f8dac344
commit d0d5a89c59

View File

@@ -185,7 +185,7 @@ public partial class CRM_CatEmpresasCRM : ClsPaginas
Archivo file = TxtExcel.getfiles().Archivos[0];
string Directorio = Server.MapPath("~") + file.path;
DataTable dt = ReadExcelFile(Directorio + file.filename, true);
DataTable dt = ModExtensiones.ReadExcelFile(Directorio + file.filename, true);
DataRowCollection Rows = dt.Rows;
ICRMService cRMService = new CRMService(System.Configuration.ConfigurationManager.ConnectionStrings["Conexion"].ConnectionString);
RequestMedioCaptacion RequestMedioCaptacion = new RequestMedioCaptacion(UsuarioActual.CveEmpresa);
@@ -291,51 +291,51 @@ public partial class CRM_CatEmpresasCRM : ClsPaginas
}
private DataTable ReadExcelFile(string flatFilePath, bool firstRowHasHeaders)
{
SpreadsheetInfo.SetLicense(ModExtensiones.SerialGemBoxSpreadsheet());
ExcelFile excelFile = ExcelFile.Load(flatFilePath);
//private DataTable ReadExcelFile(string flatFilePath, bool firstRowHasHeaders)
//{
// SpreadsheetInfo.SetLicense(ModExtensiones.SerialGemBoxSpreadsheet());
// ExcelFile excelFile = ExcelFile.Load(flatFilePath);
int unnamed = 0;
int cols;
string[] columns;
int curRow = 0;
int curCol = 0;
DataTable dataTable = new DataTable();
ExcelWorksheet worksheet = excelFile.Worksheets[0];
// int unnamed = 0;
// int cols;
// string[] columns;
// int curRow = 0;
// int curCol = 0;
// DataTable dataTable = new DataTable();
// ExcelWorksheet worksheet = excelFile.Worksheets[0];
for (cols = 0; cols <= worksheet.Rows[0].AllocatedCells.Count - 1; cols++)
{
if (firstRowHasHeaders)
{
if (worksheet.Rows[0].Cells[cols].Value != null)
dataTable.Columns.Add(worksheet.Rows[0].Cells[cols].Value.ToString().Trim());
else
dataTable.Columns.Add("Unnamed Column " + (System.Threading.Interlocked.Increment(ref unnamed)));
// for (cols = 0; cols <= worksheet.Rows[0].AllocatedCells.Count - 1; cols++)
// {
// if (firstRowHasHeaders)
// {
// if (worksheet.Rows[0].Cells[cols].Value != null)
// dataTable.Columns.Add(worksheet.Rows[0].Cells[cols].Value.ToString().Trim());
// else
// dataTable.Columns.Add("Unnamed Column " + (System.Threading.Interlocked.Increment(ref unnamed)));
curRow = 1;
}
else
dataTable.Columns.Add("Column " + (cols + 1));
}
// curRow = 1;
// }
// else
// dataTable.Columns.Add("Column " + (cols + 1));
// }
while (curRow < worksheet.Rows.Count)
{
columns = new string[cols - 1 + 1];
// while (curRow < worksheet.Rows.Count)
// {
// columns = new string[cols - 1 + 1];
for (curCol = 0; curCol <= cols - 1; curCol++)
{
if (worksheet.Rows[curRow].Cells[curCol].Value == null)
columns[curCol] = "";
else
columns[curCol] = worksheet.Rows[curRow].Cells[curCol].Value.ToString();
}
// for (curCol = 0; curCol <= cols - 1; curCol++)
// {
// if (worksheet.Rows[curRow].Cells[curCol].Value == null)
// columns[curCol] = "";
// else
// columns[curCol] = worksheet.Rows[curRow].Cells[curCol].Value.ToString();
// }
dataTable.Rows.Add(columns);
curRow += 1;
}
// dataTable.Rows.Add(columns);
// curRow += 1;
// }
return dataTable;
}
// return dataTable;
//}
}