Esempio n. 1
0
 public static string DividirCadenaDelimitada(string s, string LimiteIzquierdo, string LimiteDerecho)
 {
     try
     {
         if (s == null)
         {
             return(null);
         }
         int izq = s.IndexOf(LimiteIzquierdo);
         if (izq < 0)
         {
             return(null);
         }
         string w_str = s.Substring(izq + LimiteIzquierdo.Length);
         int    der   = w_str.IndexOf(LimiteDerecho);
         if (der < 0)
         {
             return(w_str);
         }
         return(w_str.Substring(0, der));
     }
     catch (Exception ex)
     {
         Mensajes.msgError(s, ex);
         return(null);
     }
 }
Esempio n. 2
0
        public static bool ExportarListaAExcel <T>(List <T> lista)
        {
            try
            {
                Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
                excel.Application.Workbooks.Add(true);
                Type tipo = typeof(T);
                IList <PropertyInfo> campos = new List <PropertyInfo>(tipo.GetProperties());
                int columnIndex             = 0;

                foreach (PropertyInfo campo in campos)
                {
                    columnIndex++;
                    excel.Cells[1, columnIndex] = campo.Name;
                }
                int rowIndex = 0;
                foreach (T row in lista)
                {
                    rowIndex++;
                    columnIndex = 0;
                    foreach (PropertyInfo campo in campos)
                    {
                        columnIndex++;
                        object obj = campo.GetValue(row, null);

                        if (obj == null)
                        {
                            continue;
                        }
                        string   dato = obj.ToString();
                        DateTime val;
                        if (DateTime.TryParse(dato, out val) == true)
                        {
                            dato = val.ToShortDateString();
                        }
                        Microsoft.Office.Interop.Excel.Range range = excel.Cells[rowIndex + 1, columnIndex];
                        range.Value = dato;
                        range.HorizontalAlignment = Microsoft.Office.Interop.Excel.Constants.xlLeft;
                        //excel.Cells[rowIndex + 1, ColumnIndex]
                    }
                }
                excel.Visible = true;
                return(true);
            }
            catch (Exception ex)
            {
                Mensajes.msgError(ex);
                return(false);
            }
        }
Esempio n. 3
0
        public static String DividirCadena(String s, String var, out String Izq, out String Der, Boolean opc)
        {
            try
            {
                if (s == null)
                {
                    Izq = null; Der = null; return(null);
                }
                int i = s.IndexOf(var);
                int l = var.Length;
                if (i > -1)
                {
                    Izq = s.Substring(0, i);

                    if (i < s.Length)
                    {
                        Der = s.Substring(i + l);
                    }
                    else
                    {
                        Der = null;
                    }
                }
                else
                {
                    Izq = s;
                    Der = null;
                }
                if (!opc)
                {
                    return(Izq);
                }
                else
                {
                    return(Der);
                }
            }
            catch (Exception ex)
            {
                Mensajes.msgError(s, ex);
                Der = null; Izq = null;
                return(null);
            }
        }