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