Ejemplo 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());
        }
Ejemplo 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;
        }
Ejemplo 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()));
            }
Ejemplo n.º 4
0
 public void AddWorksheet(object[] rows)
 {
     AddWorksheet(ExcelCellWrapper.FromArray(rows));
 }
Ejemplo n.º 5
0
 public void AddWorksheet(ExcelCellWrapper[] rows)
 {
     AddWorksheet(rows, "Sheet" + sheetNum++.ToString());
 }
Ejemplo n.º 6
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());
            }
Ejemplo n.º 7
0
 public ExcelWorkSheet(ExcelCellWrapper[] objects, Dictionary<string, string> headerMap)
     : this(objects)
 {
     this.headerMap = headerMap;
 }
Ejemplo n.º 8
0
 public ExcelWorkSheet(ExcelCellWrapper[] objects)
 {
     this.objects = objects;
     isDao = true;
 }
Ejemplo n.º 9
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;
        }
Ejemplo n.º 10
0
        public ExcelWorkSheet AddWorksheet(ExcelCellWrapper[] rows, string worksheetName, string headerStyle, Dictionary<string, string> headerMap, bool isDao)
        {
            foreach (ExcelCellWrapper cell in rows)
            {
                ValidateStyles(cell);
            }

            ExcelWorkSheet worksheet = new ExcelWorkSheet(rows, headerMap);
            worksheet.WorkSheetName = worksheetName;
            worksheet.objects = rows;
            worksheet.headerStyle = headerStyle;
            worksheet.isDao = isDao;
            worksheets.Add(worksheetName, worksheet);
            return worksheet;
        }
Ejemplo n.º 11
0
 public void AddWorksheet(ExcelCellWrapper[] rows, string worksheetName, string headerStyle, Dictionary<string, string> headerMap)
 {
     AddWorksheet(rows, worksheetName, headerStyle, headerMap, true);
 }
Ejemplo n.º 12
0
 public void AddWorksheet(ExcelCellWrapper[] rows, string worksheetName)
 {
     AddWorksheet(rows, worksheetName, string.Empty, new Dictionary<string,string>());
 }