Esempio n. 1
0
        /// <summary>
        /// Output data about the objects in the specified array.  All objects should be of the same type
        /// or at least be objects with identical properties to ensure proper column alignment.
        /// </summary>
        /// <param name="args">the array of objects to ouput properties of</param>
        /// <returns>An Excel readable XMLSS string.  When written to a file later versions of
        /// Excel should natively recognize the xml as a valid Excel readable spreadsheet.</returns>
        public static string ToXMLSS(object[] args, string workSheetName)
        {
            if (string.IsNullOrEmpty(workSheetName))
            {
                workSheetName = "Sheet1";
            }

            StringBuilder output = new StringBuilder();

            OpenXMLSS(workSheetName, output);

            Type type = null;

            if (args.Length > 0)
            {
                type = args[0].GetType();
                output.AppendLine(MakeHeader(type));

                foreach (object arg in args)
                {
                    ExcelCellWrapper obj         = arg as ExcelCellWrapper;
                    object           valueHolder = obj == null ? arg : obj.Object;

                    List <string> propValues = new List <string>();
                    List <string> styles     = new List <string>();

                    PropertyInfo[] props = type.GetProperties();
                    foreach (PropertyInfo prop in props)
                    {
                        if (prop.GetCustomAttributes(typeof(DaoIgnore), true).Length > 0)
                        {
                            continue;
                        }

                        object propVal = prop.GetValue(valueHolder, null);

                        propValues.Add(propVal == null ? "": propVal.ToString());

                        if (obj != null)
                        {
                            styles.Add(obj.GetStyle(prop.Name));
                        }
                    }

                    output.AppendLine(MakeRow(propValues.ToArray(), styles.ToArray()));
                }
            }
            CloseXMLSS(output);

            return(output.ToString());
        }
Esempio n. 2
0
        private void ValidateStyles(ExcelCellWrapper item)
        {
            //bool retVal = true;
            PropertyInfo[] properties = item.Object.GetType().GetProperties();
            foreach (PropertyInfo property in properties)
            {
                string style = item.GetStyle(property.Name);
                if (!string.IsNullOrEmpty(style) &&
                    !this.styles.ContainsKey(style))
                {
                    item.SetStyle(property.Name, string.Empty);
                }
            }

            //return retVal;
        }
Esempio n. 3
0
            private string MakeRow(ExcelCellWrapper cell)
            {
                List <string> cellContents = new List <string>();
                List <string> styles       = new List <string>();

                foreach (PropertyInfo property in cell.Object.GetType().GetProperties())
                {
                    if (ShouldIgnoreProperty(property))
                    {
                        continue;
                    }

                    object propVal = property.GetValue(cell.Object, null);
                    cellContents.Add(propVal == null ? "": propVal.ToString());//.ToString());
                    styles.Add(cell.GetStyle(property.Name));
                }

                return(MakeRow(cellContents.ToArray(), styles.ToArray()));
            }
Esempio n. 4
0
            private string MakeRow(ExcelCellWrapper cell)
            {
                List<string> cellContents = new List<string>();
                List<string> styles = new List<string>();
                foreach (PropertyInfo property in cell.Object.GetType().GetProperties())
                {
                    if (ShouldIgnoreProperty(property))
                        continue;

                    object propVal = property.GetValue(cell.Object, null);
                    cellContents.Add(propVal == null ? "": propVal.ToString());//.ToString());
                    styles.Add(cell.GetStyle(property.Name));
                }

                return MakeRow(cellContents.ToArray(), styles.ToArray());
            }
Esempio n. 5
0
        private void ValidateStyles(ExcelCellWrapper item)
        {
            //bool retVal = true;
            PropertyInfo[] properties = item.Object.GetType().GetProperties();
            foreach (PropertyInfo property in properties)
            {
                string style = item.GetStyle(property.Name);
                if (!string.IsNullOrEmpty(style) &&
                    !this.styles.ContainsKey(style))
                    item.SetStyle(property.Name, string.Empty);
            }

            //return retVal;
        }