public bool UpdatePersonFoto(IEngineTool Tool, IEngineHttp Funcion) { Excel.Application xlApp = new Excel.Application(); Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"C:\Users\ASUS\Downloads\CARNETIZACION\Rosa\List\NUEVO.xlsx"); Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1]; Excel.Range xlRange = xlWorksheet.UsedRange; xlApp.DisplayAlerts = false; int rowCount = xlRange.Rows.Count; int colCount = xlRange.Columns.Count; string strValue = string.Empty; bool validate = false; string file = string.Empty; string foto = string.Empty; string dni = string.Empty; string s = "#"; for (int fila = 2; fila <= rowCount; fila++) { strValue = string.Empty; for (int columna = 1; columna <= colCount; columna++) { try { if (xlRange.Cells[fila, columna] != null) { if (columna == 1)//foto { if (xlRange.Cells[fila, columna].Value != null) { var g = (xlRange.Cells[fila, columna].Value2.ToString()).Replace("/", "#").Trim(); string[] part = g.Split('#'); file = @"C:\Users\ASUS\Downloads\CARNETIZACION\Rosa\List\fotopeq" + part[1].Trim(); validate = Tool.ExistsFile(file); if (validate) { foto = file; } else { file = @"C:\Users\ASUS\Downloads\CARNETIZACION\Rosa\List\fotopeq" + part[1].Trim(); foto = file; } } else { file = "NO_DEFINIDO"; foto = file; } strValue = strValue + foto + s; } else if (columna == 2)//dni documento { try { if (xlRange.Cells[fila, columna].Value2 != null) { dni = xlRange.Cells[fila, columna].Value2.ToString().Trim(); } else { dni = xlRange.Cells[fila, columna].Value2.ToString().Trim(); } } catch { dni = "-"; } strValue = strValue + dni + s; } } //************************************************************************************************************************************************************************* } catch (Exception ex) { string err = ex.ToString(); } } foto = Tool.ConvertImgTo64Img(foto); validate = Funcion.UpdatePersonFoto(dni, foto); strValue = string.Empty; } GC.Collect(); GC.WaitForPendingFinalizers(); while (Marshal.ReleaseComObject(xlRange) != 0) { ; } while (Marshal.ReleaseComObject(xlWorksheet) != 0) { ; } xlWorkbook.Close(); while (Marshal.ReleaseComObject(xlWorkbook) != 0) { ; } xlApp.Quit(); while (Marshal.ReleaseComObject(xlApp) != 0) { ; } ReadWriteTxt(@"C:\Users\ASUS\Downloads\CARNETIZACION\Rosa\List\NUEVO.xlsx"); return(validate); }
public void CreateQRImagen(string source, string pathDestino) { string strBase64 = Tool.ConvertImgTo64Img(source); Tool.CreateQrCode(strBase64, pathDestino); }
public bool CreateFileXlsx(List <Person> persons, string pathFile, IEngineTool Tool) { bool resultado = false; Excel.Application excel = default(Excel.Application); Excel.Workbook libro = default(Excel.Workbook); Excel.Worksheet hoja = default(Excel.Worksheet); excel = new Excel.Application(); excel.DisplayAlerts = false; try { libro = excel.Workbooks.Add(); hoja = libro.Worksheets[1]; hoja.Activate(); hoja.Range["A1"].Value = "FOTO"; hoja.Range["B1"].Value = "NOMBRE"; hoja.Range["C1"].Value = "APELLIDO"; hoja.Range["D1"].Value = "DNI"; hoja.Range["E1"].Value = "MATRICULA"; hoja.Range["F1"].Value = "RH"; hoja.Range["G1"].Value = "GRADO"; hoja.Range["H1"].Value = "GRUPO"; hoja.Range["I1"].Value = "QR"; int n = 2; string foto64 = string.Empty; string sourceQr = string.Empty; string qr64 = string.Empty; string pathFoto = string.Empty; string pathQr = string.Empty; foreach (Person p in persons) { try { foto64 = Tool.ConvertImgTo64Img(p.Foto); sourceQr = p.Nombre + "#" + p.Apellido + "#" + p.Dni; sourceQr = Tool.ConvertirBase64(sourceQr); p.Qr = Tool.CreateQrCode(sourceQr, Valor.PathFolderImageQr() + @"\" + p.Dni + ".png"); qr64 = Tool.ConvertImgTo64Img(Valor.PathFolderImageQr() + @"\" + p.Dni + ".png"); var f = p.Foto.Split('\\'); var q = p.Qr.Split('\\'); hoja.Range["A" + n].Value = "FOTO/" + f[f.Length - 1]; hoja.Range["B" + n].Value = p.Nombre; hoja.Range["C" + n].Value = p.Apellido; hoja.Range["D" + n].Value = p.Dni; hoja.Range["E" + n].Value = p.Matricula; hoja.Range["F" + n].Value = p.Rh; hoja.Range["G" + n].Value = p.Grado; hoja.Range["H" + n].Value = p.Grupo; hoja.Range["I" + n].Value = "QR/" + q[q.Length - 1];; p.Foto = foto64; p.Qr = qr64; n++; } catch (Exception ex) { MessageBox.Show("Error: " + ex.ToString()); } } excel.ActiveWindow.Zoom = 100; excel.Columns.AutoFit(); excel.Rows.AutoFit(); libro.SaveAs(pathFile); ReadWriteTxt(pathFile); excel.Quit(); Valor.SetPersons(persons); resultado = true; } catch (Exception ex) { MessageBox.Show("Error: " + ex.ToString()); } return(resultado); }