/// <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()); }
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; }
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())); }
public void AddWorksheet(object[] rows) { AddWorksheet(ExcelCellWrapper.FromArray(rows)); }
public void AddWorksheet(ExcelCellWrapper[] rows) { AddWorksheet(rows, "Sheet" + sheetNum++.ToString()); }
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()); }
public ExcelWorkSheet(ExcelCellWrapper[] objects, Dictionary<string, string> headerMap) : this(objects) { this.headerMap = headerMap; }
public ExcelWorkSheet(ExcelCellWrapper[] objects) { this.objects = objects; isDao = true; }
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; }
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; }
public void AddWorksheet(ExcelCellWrapper[] rows, string worksheetName, string headerStyle, Dictionary<string, string> headerMap) { AddWorksheet(rows, worksheetName, headerStyle, headerMap, true); }
public void AddWorksheet(ExcelCellWrapper[] rows, string worksheetName) { AddWorksheet(rows, worksheetName, string.Empty, new Dictionary<string,string>()); }