public AddDataBlockViewModel(ModelAssociation targetAssociation, ModelClass targetClass) { TargetAssociation = targetAssociation; TargetClass = targetClass; string multiplicity = targetAssociation.Members.FirstOrDefault(m => m.ClassName.Equals(targetClass.Name)).Multiplicity; SheetBlock = new Model.SheetBlock() { Type = multiplicity.Equals("1") ? "single" : "input" }; TypeString = SheetBlock.Type; AssociationString = string.Format("{0} {1} {2} {3}", TargetAssociation.Members[0].ClassName, TargetAssociation.Members[0].Multiplicity, TargetAssociation.Members[1].Multiplicity, TargetAssociation.Members[1].ClassName); }
public void AddDataBlock(SheetTab sheetTab, SheetBlock sheetBlock) { try { if (sheetBlock.Type == "input" || sheetBlock.Type == "single") { int nColumns = sheetBlock.SheetColumns.Count; if (nColumns <= 0) { return; } sheetTab.Worksheet.Cells[i, j] = sheetBlock.Name; i++; Excel.Range bBegin = (Excel.Range)sheetTab.Worksheet.Cells[i, j]; Excel.Range bEnd = (Excel.Range)sheetTab.Worksheet.Cells[i, nColumns]; Excel.ListObject interopList = sheetTab.Worksheet.ListObjects.Add( Excel.XlListObjectSourceType.xlSrcRange, sheetTab.Worksheet.Range[bBegin, bEnd]); interopList.Name = sheetBlock.Name != null ? sheetBlock.Name : ""; interopList.ShowTotals = true; foreach (SheetColumn sheetColumn in sheetBlock.SheetColumns) { interopList.ListColumns[j].Name = sheetColumn.ModelAttribute.Name; interopList.ListColumns[j].TotalsCalculation = sheetColumn.HasTotal ? GetTotalsCalculation(sheetColumn.TotalType) : Excel.XlTotalsCalculation.xlTotalsCalculationNone; j++; } } //else if (sheetBlock.Type == "single") { } else // sheetBlock.Type == "total" { } i += 4; j = 1; } catch (Exception ex) { } }