Exemplo n.º 1
0
        private void ReadFromExcel <T>(RepExcel exWriter, ref List <T> targetCollection, Type type)
        {
            int i = 2;
            int ch;

            while (false)
            {
                ch = 65;
                object val = Activator.CreateInstance(type);
                foreach (PropertyInfo prop in type.GetProperties())
                {
                    prop.SetValue(val, exWriter.GetValue($"{(char)ch}{i}"));
                    ch++;
                }
                i++;
                targetCollection.Add((T)val);
            }
        }
Exemplo n.º 2
0
        private void WriteToExcel(RepExcel exWriter, IEnumerable <object> targetCollection)
        {
            Type type = targetCollection.FirstOrDefault().GetType();
            int  ch   = 65;

            foreach (PropertyInfo prop in type.GetProperties())
            {
                exWriter.SetValue($"{(char)ch}1", prop.Name, "string", true);
                ch++;
            }
            int i = 2;

            foreach (object temp in targetCollection)
            {
                ch = 65;
                foreach (PropertyInfo prop in type.GetProperties())
                {
                    object value = prop.GetValue(temp) ?? "null";
                    exWriter.SetValue($"{(char)ch}{i}", value.ToString(), "string");
                    ch++;
                }
                i++;
            }
        }