所以我为每个循环嵌套了这些,第二个循环采用第一个循环中计算的“访问”。但是,当它输出信息时,它会进行第一次访问,然后换页并继续循环,打印出第一次循环中出现的所有访问。如何让它在工作表 1 上打印所有访问,然后移动到嵌套循环并打印出这些结果?
int r = 1;
int j = 1;
int cell = 0;
//loop that places Visit on Sheet 1 of Excel
for (int i = 1; i < visits.Count(); i++)
{
Visit visit = visits[i];
decimal? charges = visit.TotalCharges();
decimal? payments = visit.TotalPayments();
decimal? totAdj = visit.PaymentAdjustments.Where(x => x.nrv_cd.Trim() == "C01").Sum(s => s.pmt_pst_at);
decimal? actbalance = charges - (payments + totAdj);
CareGiver attending = visit.AttendingPhysicianCareGiver();
workbook.AddCell(r, cell++, visit.Person.DisplayName());
workbook.AddCell(r, cell++, visit.vst_ext_id.Trim());
workbook.AddCell(r, cell++, visit.LosFormatted());
workbook.AddCell(r, cell++, visit.CodeDetail.cod_dtl_ds);
workbook.AddCell(r, cell++, visit.CodeDetail.cod_dtl_ext_id.Trim());
workbook.AddCell(r, cell++, charges);
workbook.AddCell(r, cell++, payments);
workbook.AddCell(r, cell++, totAdj);
workbook.AddCell(r, cell++, actbalance);
r++;
workbook.ChangeWorksheet(2);
//when moving to this nested loop, it picks up all charge codes for that visit
foreach (Charge c in visit.Charges)
{
workbook.AddCell(j, 0, visit.vst_ext_id.Trim());
workbook.AddCell(j, 1, c.ChargeDefinition.chg_cod_ext_id.Trim());
j++;
}
//when moving to this nested loop, it picks up all adjustment codes for that visit
foreach (PaymentAdjustment pa in visit.PaymentAdjustments)
{
workbook.AddCell(j, 0, visit.vst_ext_id.Trim());
workbook.AddCell(j, 1, pa.ChargeDefinition.chg_cod_ext_id.Trim());
j++;
}
workbook.ChangeWorksheet(1);