example of output desired:
AHS 20112
AHS 20114
BREAK
BUS 20024
BUS 20025
BUS 20154
BUS 20187
BREAK
CRJ 20006
CRJ 20009
etc...
etc...
foreach (FacultyElements F in db._DataHolder)
{
if (PreviousSubCode == string.Empty)
{
Debug.WriteLine(F.subjCode + " " + F.CRN);
}
else
{
r++;
if (PreviousSubCode == F.subjCode)
{
Debug.WriteLine(F.subjCode + " " + F.CRN);
objTable.Cell(r, 1).Range.Text = F.subjCode;
objTable.Cell(r, 2).Range.Text = F.sessCode;
objTable.Cell(r, 3).Range.Text = F.courseNum;
objTable.Cell(r, 4).Range.Text = F.seqNum;
objTable.Cell(r, 5).Range.Text = F.PtrmCode;
objTable.Cell(r, 6).Range.Text = F.CRN;
objTable.Cell(r, 7).Range.Text = F.courseTitle;
//dual fields
objTable.Cell(r, 8).Range.Text = "";
objTable.Cell(r, 9).Range.Text = "";
objTable.Cell(r, 10).Range.Text = "";
objTable.Cell(r, 11).Range.Text = F.CourseHours;
}
else
{
Debug.WriteLine("BREAK");
Debug.WriteLine(F.subjCode + " " + F.CRN);
objTable.Cell(r, 1).Range.Text = F.subjCode;
objTable.Cell(r, 2).Range.Text = F.sessCode;
objTable.Cell(r, 3).Range.Text = F.courseNum;
objTable.Cell(r, 4).Range.Text = F.seqNum;
objTable.Cell(r, 5).Range.Text = F.PtrmCode;
objTable.Cell(r, 6).Range.Text = F.CRN;
objTable.Cell(r, 7).Range.Text = F.courseTitle;
//dual fields
objTable.Cell(r, 8).Range.Text = "";
objTable.Cell(r, 9).Range.Text = "";
objTable.Cell(r, 10).Range.Text = "";
objTable.Cell(r, 11).Range.Text = F.CourseHours;
}
}
PreviousSubCode = F.subjCode;
}
Lorine Appleby38 pointsPosted Dec 17, 2014, 12:33 AM EST
int r = 1; foreach (FacultyElements F in db._DataHolder) { if (F.subjCode == "BREAK") { objTable.Rows.Add(); objTable.Rows[r].Range.InsertBreak(WdBreakType.wdPageBreak); objTable = document.Tables.Add(Range: para.Range, NumRows: 1, NumColumns: 11); r = 1; } if (r != 1) objTable.Rows.Add(); objTable.Cell(r, 1).Range.Text = F.subjCode; objTable.Cell(r, 2).Range.Text = F.sessCode; objTable.Cell(r, 3).Range.Text = F.courseNum; objTable.Cell(r, 4).Range.Text = F.seqNum; objTable.Cell(r, 5).Range.Text = F.PtrmCode; objTable.Cell(r, 6).Range.Text = F.CRN; objTable.Cell(r, 7).Range.Text = F.courseTitle; objTable.Cell(r, 8).Range.Text = ""; objTable.Cell(r, 9).Range.Text = ""; objTable.Cell(r, 10).Range.Text = ""; objTable.Cell(r, 11).Range.Text = F.CourseHours; r++; } string file = Path.Combine( Environment.GetFolderPath( Environment.SpecialFolder.Desktop), "Sample.docx"); document.SaveAs2(file); document.Close(); application.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(application);Also if interested I would advise you to take a look at this alternative approach, the code uses this word component in C#:
Section section = document.Sections[0]; foreach (FacultyElements F in db._DataHolder) { if (F.subjCode == "BREAK") { section.Blocks.Add( new Paragraph(document, new SpecialCharacter(document, SpecialCharacterType.PageBreak))); table = new Table(document); section.Blocks.Add(table); } table.Rows.Add( new TableRow(document, new TableCell(document, new Paragraph(document, F.subjCode)), new TableCell(document, new Paragraph(document, F.courseNum)), new TableCell(document, new Paragraph(document, F.seqNum)), new TableCell(document, new Paragraph(document, F.PtrmCode)), new TableCell(document, new Paragraph(document, F.CRN)), new TableCell(document, new Paragraph(document, F.courseTitle)), new TableCell(document, new Paragraph(document, string.Empty)), new TableCell(document, new Paragraph(document, string.Empty)), new TableCell(document, new Paragraph(document, string.Empty)), new TableCell(document, new Paragraph(document, F.CourseHours)))); } document.Save( Path.Combine( Environment.GetFolderPath( Environment.SpecialFolder.Desktop), "Sample.docx"));Lorine