예제 #1
0
        public void PopulateSpreadsheet(MappingConfig config, SpreadsheetDocument spreadsheet)
        {
            var orderedHeadings = new List <ExcelHeading>(headings);

            /*
             * orderedHeadings.Sort((objX, objY) =>
             * {
             *  if (objX.Group == null && objY.Group == null)
             *  {
             *      int objXIndex = config.Column.IndexOf(objX.Column);
             *      int objYIndex = config.Column.IndexOf(objY.Column);
             *
             *      return objXIndex.CompareTo(objYIndex);
             *  }
             *  else if (objX.Group == objY.Group)
             *  {
             *      if (objX.DataIndex == objY.DataIndex)
             *      {
             *          int objXIndex = objX.Group.Column.IndexOf(objX.Column);
             *          int objYIndex = objX.Group.Column.IndexOf(objY.Column);
             *
             *          return objXIndex.CompareTo(objYIndex);
             *      }
             *
             *      return objX.DataIndex.CompareTo(objY.DataIndex);
             *  }
             *
             *  var parentsX = objX.Group == null || objX.Group.Parent == null ? config.Group : objX.Group.Parent.Group;
             *  var parentsY = objY.Group == null || objY.Group.Parent == null ? config.Group : objY.Group.Parent.Group;
             *
             *  int groupXIndex = parentsX.IndexOf(objX.Group);
             *  int groupYIndex = parentsY.IndexOf(objY.Group);
             *
             *  return groupXIndex.CompareTo(groupYIndex);
             * });
             */

            PopulateHeaders(config, spreadsheet, orderedHeadings);

            foreach (var row in rows)
            {
                var excelDataRow = new Row();
                spreadsheet.WorkbookPart.WorksheetParts.First().Worksheet.First().AppendChild(excelDataRow);

                Cell fileNameCell = new Cell()
                {
                    DataType  = CellValues.String,
                    CellValue = new CellValue(row.FileName)
                };

                excelDataRow.AppendChild(fileNameCell);

                foreach (var heading in orderedHeadings)
                {
                    var datas = row.Data.Where(y => y.Column == heading.Column).ToArray();

                    if (datas.Length - 1 < heading.DataIndex)
                    {
                        excelDataRow.AppendChild(new Cell()
                        {
                            DataType  = CellValues.String,
                            CellValue = new CellValue(string.Empty)
                        });
                        continue;
                    }

                    var data = datas[heading.DataIndex];

                    Cell cell = new Cell()
                    {
                        DataType  = CellValues.String,
                        CellValue = new CellValue(data.Data)
                    };

                    if (data.IsBold)
                    {
                        cell.StyleIndex = 1;
                    }

                    excelDataRow.AppendChild(cell);
                }
            }
        }
예제 #2
0
 public static bool LoadFromFile(string fileName, out MappingConfig obj)
 {
     System.Exception exception = null;
     return(LoadFromFile(fileName, out obj, out exception));
 }
        private static void ValidateGroup(MappingGroup group)
        {
            MappingConfig.ValidateColumns(group.TableName, group.Column);

            group.Group.ForEach(g => MappingConfig.ValidateGroup(g));
        }
예제 #4
0
 public static bool Deserialize(string input, out MappingConfig obj)
 {
     System.Exception exception = null;
     return(Deserialize(input, out obj, out exception));
 }