public override void ExecuteResult(ControllerContext context) { var Response = context.HttpContext.Response; var q = ExcelExportModel.List(id); if (!q.Any()) { Response.Write("no data found"); return; } using (var ms = new MemoryStream()) { var col = 0; var row = 0; var tt = dd.InsertTable(q.Count / 3 + (q.Count % 3 > 0 ? 1 : 0), 6); tt.AutoFit = AutoFit.ColumnWidth; for (var r = 0; r < tt.RowCount; r++) { var rr = tt.Rows[r]; rr.Height = Pixels(pa.RowHeight); for (var i = 0; i < 6; i++) { var c = rr.Cells[i]; c.MarginRight = 0; if (i % 2 == 0) { c.Width = Pixels(pa.PicWidth); c.MarginLeft = 0; } else { c.Width = Pixels(pa.LabelWidth - pa.PicWidth); c.MarginLeft = Pixels(pa.SpacerWidth); } } } foreach (var p in q) { col = FillCell(tt.Rows[row], col, p); if (col < 6) { continue; } row++; col = 0; } dd.SaveAs(ms); Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; Response.AddHeader("content-disposition", "filename=picturedir.docx"); Response.AddHeader("content-length", ms.Length.ToString()); Response.BinaryWrite(ms.ToArray()); Response.End(); } }
public void ExcelListShouldNotHaveDeceased() { var requestManager = FakeRequestManager.Create(); var db = requestManager.CurrentDatabase; var family = new Family(); db.Families.InsertOnSubmit(family); db.SubmitChanges(); var hoh = new Person { Family = family, FirstName = RandomString(), LastName = RandomString(), EmailAddress = RandomString() + "@example.com", MemberStatusId = MemberStatusCode.Member, PositionInFamilyId = PositionInFamily.PrimaryAdult }; var child = new Person { Family = family, FirstName = RandomString(), LastName = RandomString(), EmailAddress = RandomString() + "@example.com", DeceasedDate = DateTime.Now, MemberStatusId = MemberStatusCode.Member, PositionInFamilyId = PositionInFamily.Child }; db.People.InsertOnSubmit(hoh); db.People.InsertOnSubmit(child); db.SubmitChanges(); string code = "FamilyId = " + family.FamilyId; var query = QueryModel.QueryCode(db, code); query.Count().ShouldBeGreaterThan(0); var ExcelPics = ExcelExportModel.List(query.QueryId.Value); ExcelPics.Where(p => p.Children.HasValue()).Count().ShouldBe(0); db.PurgePerson(hoh.PeopleId); db.PurgePerson(child.PeopleId); db.Families.DeleteOnSubmit(family); db.SubmitChanges(); }