/// <summary> /// Updates the header of the document /// </summary> /// <param name="PobjDoc"></param> private void updateHeader(Word.Document PobjDoc) { try { switch (MobjSettings.GetTemplateType()) { case AddinSettings.TemplateType.FullWeek: case AddinSettings.TemplateType.WorkWeek: PobjDoc.FindReplace("<<header>>", "Calendar for Week of " + MobjStart.Day.GetOrdinal() + " to " + MobjEnd.Day.GetOrdinal()); break; case AddinSettings.TemplateType.Month: PobjDoc.FindReplace("<<header>>", "Calendar for Month of " + MobjStart.Month.GetMonthName() + ", " + MobjEnd.Year.ToString()); break; case AddinSettings.TemplateType.Day: PobjDoc.FindReplace("<<header>>", "Day of " + MobjStart.Month.GetMonthName() + " the " + MobjStart.Day.GetOrdinal()); break; } if (MobjSettings.ShowHeader) { if (MobjSettings.Recipients.Count == 1) { if (MobjSettings.Recipients[0].ShowName) { PobjDoc.FindReplace("<<name>>", "Calendar of " + MobjSettings.Recipients[0].RecipientName); } else { PobjDoc.FindReplace("<<name>>", "Calendar of " + MobjSettings.Recipients[0].DisplayName); } } else { PobjDoc.FindReplace("<<name>>", "Calendars of " + MobjSettings.Recipients.ToStringOfNamesWithSymbols()); } } else { // delete the header row and lead paragraph // this is the ONLY troubling part, we have to select // the range and type a backspace Word.Range LobjRange = PobjDoc.FindReplace("<<name>>", ""); LobjRange.Select(); LobjRange.Application.Selection.TypeBackspace(); } } catch (Exception PobjEx) { PobjEx.Log(true, "Unable to update the header."); } }
/// <summary> /// Collect a workweeks worrth of data from the selected calendars /// and then open the template and replace each of the days fields /// </summary> private void exportDays(int PintStart = 1) { try { Common.LoadProgress(MobjAppointments.Count, "Preparing..."); Word.Document LobjDoc = openDocument(); updateHeader(LobjDoc); int LintCount = PintStart; foreach (DailyAppointments LobjDay in MobjAppointments) { Common.IncrementProgress("Exporting day " + LobjDay.Date.ToLongDateString() + "..."); int LintNumber = LobjDay.Appointments.Count; // update the day number - usually for monthly LobjDoc.FindReplace("<<day" + LintCount.ToString() + ">>", (LintCount - PintStart + 1).GetOrdinal()); foreach (ExtendedAppointment LobjAppt in LobjDay.Appointments) { // Do we only care about shared meetings? // is this a shared meetings between two or more of the // recipients in this export? if (LobjAppt.Recipients.Count == 1 && MobjSettings.ExportWhat == AddinSettings.ExportType.Shared) { continue; // skip because we only want to see shared meetings } Word.Range LobjTimeRange = LobjDoc.FindReplace( "<<time" + LintCount.ToString() + ">>", LobjAppt.Start.Hour.ToString("00") + ":" + LobjAppt.Start.Minute.ToString("00") + " - " + LobjAppt.End.Hour.ToString("00") + ":" + LobjAppt.End.Minute.ToString("00")); Word.Range LobjTitleRange = null; string LstrSymbols = " (" + LobjAppt.Recipients.ToStringOfSymbols() + ")"; string LstrData = LobjAppt.Subject; // see if we need to obfuscate the meeting information if (MobjSettings.DisplayTimeOnly) { // we only going to show a generic -- Meeting -- or // -- Appointment -- if (LobjAppt.IsMeeting) { LstrData = " -- MEETING --"; } else { LstrData = " -- APPOINTMENT --"; } } // is there is only one recipient, we do not // need symbols so lets remove them... if (MobjSettings.Recipients.Count == 1) { // we do not need symbols LstrSymbols = ""; } // if there is no location - OR // we want to hide the lcoations if (string.IsNullOrEmpty(LobjAppt.Location) || MobjSettings.ShowLocation == false) { // export without a location LobjTitleRange = LobjDoc.FindReplace( "<<title" + LintCount.ToString() + ">>", LstrData + LstrSymbols); } else { // otherwise export with the location LobjTitleRange = LobjDoc.FindReplace( "<<title" + LintCount.ToString() + ">>", LstrData + LstrSymbols + "[" + LobjAppt.Location + "]"); } // add emphasis if (LobjAppt.Recurring && MobjSettings.EmphasizeRecurring) { LobjTitleRange.Font.Italic = 1; LobjTimeRange.Font.Italic = 1; } LintNumber--; // if there are more appointments for the same day // we want to add a new row to the inner table for that day if (LintNumber > 0) { if (LobjTimeRange.Tables.Count > 0) { Word.Row LobjRow = LobjTimeRange.Rows.Add(); // add our find items LobjRow.Cells[1].Range.Text = "<<time" + LintCount.ToString() + ">>"; LobjRow.Cells[2].Range.Text = "<<title" + LintCount.ToString() + ">>"; } else { LobjTimeRange.InsertAfter("<<time" + LintCount.ToString() + ">>"); LobjTitleRange.InsertAfter("<<title" + LintCount.ToString() + ">>"); } } } // increment last LintCount++; } // cleanup - we remove any boilerplate items that were not used for (int LintX = 1; LintX <= 42; LintX++) { LobjDoc.FindReplace("<<time" + LintX.ToString() + ">>", ""); LobjDoc.FindReplace("<<title" + LintX.ToString() + ">>", ""); LobjDoc.FindReplace("<<day" + LintX.ToString() + ">>", ""); } // now delete empty tables - the cleans up unused days foreach (Word.Table LobjTable in LobjDoc.Tables) { LobjTable.DeleteEmpty(); } colorCode(LobjDoc); // done LobjDoc.Application.Visible = true; Common.CloseProgress(); } catch (Exception PobjEx) { throw new Exception("Failed exporting the week. " + PobjEx.Message); } }