public bool ProcessWholeParagraphs(OfficeDocumentProcessor aWordProcessor, Word.Paragraphs aParagraphs)
        {
            foreach (Word.Paragraph aParagraph in aParagraphs)
            {
                // get the Range object for this paragraph
                Word.Range aParagraphRange = aParagraph.Range;

                // if we're picking up where we left off and we're not there yet...
                int nCharIndex = 0;
                if (aWordProcessor.AreLeftOvers)
                {
                    if (aWordProcessor.LeftOvers.Start > aParagraphRange.End)
                    {
                        continue;   // skip to the next paragraph
                    }
                    nCharIndex = aWordProcessor.LeftOvers.StartIndex;
                    aWordProcessor.LeftOvers = null; // turn off "left overs"
                }

                WordRange aRunRange  = new WordRange(aParagraphRange);
                int       nEndIndex  = --aRunRange.EndIndex;
                int       nLastIndex = nCharIndex;

                // exclude the paragraph end and process it as a whole unit (we may have to do this multiple times
                bool bStop = false;
                while (!bStop && (nCharIndex < nEndIndex))
                {
                    aRunRange.StartIndex = nCharIndex;
                    if (aRunRange.EndIndex != nEndIndex)
                    {
                        aRunRange.EndIndex = nEndIndex;
                    }

                    nLastIndex = nCharIndex;

                    System.Diagnostics.Trace.WriteLine(String.Format("Start: {0}, End: {1}, text: {2}, length: {3}",
                                                                     aRunRange.Start, aRunRange.End, aRunRange.Text, aRunRange.Text.Length));

                    if (!aWordProcessor.Process(aRunRange, ref nCharIndex))
                    {
                        aWordProcessor.LeftOvers = aRunRange;
                        return(false);
                    }

                    if (nLastIndex == nCharIndex)
                    {
                        break;
                    }
                }
            }

            return(true);
        }
        public bool ProcessParagraphsIsoFormat(OfficeDocumentProcessor aWordProcessor, Word.Paragraphs aParagraphs)
        {
            foreach (Word.Paragraph aParagraph in aParagraphs)
            {
                // get the Range object for this paragraph
                Word.Range aParagraphRange = aParagraph.Range;

                // if we're picking up where we left off and we're not there yet...
                int nCharIndex = 0;
                if (aWordProcessor.AreLeftOvers)
                {
                    if (aWordProcessor.LeftOvers.Start > aParagraphRange.End)
                    {
                        continue;                           // skip to the next paragraph
                    }
                    nCharIndex = aWordProcessor.LeftOvers.StartIndex;
                    aWordProcessor.LeftOvers = null;                     // turn off "left overs"
                }

                WordRange aRunRange   = new WordRange(aParagraphRange);
                int       nStartIndex = aRunRange.StartIndex;
                System.Diagnostics.Debug.Assert(nStartIndex == 0);

                // if we have mixed character formatting, then use a binary search algorithm to find
                //	the maximum run.
                if (MixedCharacterFormatting(aRunRange))
                {
                    int nWidth = aRunRange.EndIndex / 2;

                    do
                    {
                        aRunRange.EndIndex++;
                    } while (!MixedCharacterFormatting(aRunRange));

                    aRunRange.EndIndex--;                       // back up one
                }
                else
                {
                    // the whole paragraph seems to be iso formatted, so exclude the paragraph end and
                    // process it as a whole unit
                    aRunRange.EndIndex--;
                    if (!aWordProcessor.Process(aRunRange, ref nCharIndex))
                    {
                        aWordProcessor.LeftOvers = aRunRange;
                        return(false);
                    }
                }
            }

            return(true);
        }
Example #3
0
        public override bool ProcessWordByWord(OfficeDocumentProcessor aWordProcessor)
        {
            if (aWordProcessor.AreLeftOvers)
            {
                DialogResult res = MessageBox.Show("Click 'Yes' to restart where you left off, 'No' to start over at the top, and 'Cancel' to quit", Connect.cstrCaption, MessageBoxButtons.YesNoCancel);
                if (res == DialogResult.No)
                {
                    aWordProcessor.LeftOvers = null;
                }
                else if (res == DialogResult.Cancel)
                {
                    return(true);
                }
            }

            int nCharIndex = 0;             // don't care

            foreach (Excel.Range aArea in Document.Areas)
            {
                foreach (Excel.Range aColumn in aArea.Columns)
                {
                    if (aWordProcessor.AreLeftOvers && (aWordProcessor.LeftOvers.End > aColumn.Column))
                    {
                        continue;
                    }

                    foreach (Excel.Range aRow in aColumn.Rows)
                    {
                        if ((aWordProcessor.AreLeftOvers && (aWordProcessor.LeftOvers.Start > aRow.Row)) ||
                            (String.IsNullOrEmpty((string)aRow.Text)))
                        {
                            continue;
                        }

                        ExcelRange aCellRange = new ExcelRange(aRow);
                        aWordProcessor.LeftOvers = aCellRange;

                        if (!aWordProcessor.Process(aCellRange, ref nCharIndex))
                        {
                            return(false);
                        }
                    }

                    aWordProcessor.LeftOvers = null;
                }
            }

            return(true);
        }
        public override bool ProcessWordByWord(OfficeDocumentProcessor aWordProcessor)
        {
            if (Document.Selection.Type == Pub.PbSelectionType.pbSelectionNone)
            {
                throw new ApplicationException("Nothing selected!");
            }

            PubRange      aSelectionRange = (PubRange)SelectionRange;
            PubParagraphs aParagraphs     = aSelectionRange.Paragraphs;

            if (aParagraphs.Count > 1)
            {
                return(ProcessParagraphs(aWordProcessor, aParagraphs));
            }
            else
            {
                int nCharIndex = 0;
                return(aWordProcessor.Process(aSelectionRange, ref nCharIndex));
            }
        }
Example #5
0
        public override bool ProcessWordByWord(OfficeDocumentProcessor aWordProcessor)
        {
            Document.MoveFirst(); // to avoid an error on the first 'Edit'
            int nDontCare = 0;    // don't care

            while (!Document.EOF)
            {
                dao.Fields aFields = Document.Fields;
                dao.Field  aField  = aFields[m_strFieldName];
                if (aField.Value != System.DBNull.Value)
                {
                    AccessRange aWordRange = new AccessRange(aField, this);

                    try
                    {
                        if (!aWordProcessor.Process(aWordRange, ref nDontCare))
                        {
                            return(false);
                        }
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                    finally
                    {
                        // this gets called whether we successfully process the word or not,
                        //  whether we're returning 'false' (in the try) or not, and whether we
                        //  have an exception or not... just exactly what we want, or MSAccess
                        //  process won't release when we exit.
                        OfficeApp.ReleaseComObject(aField);
                        OfficeApp.ReleaseComObject(aFields);
                    }
                }

                Document.MoveNext();
            }

            return(true);
        }
Example #6
0
        protected bool ProcessWholeRange(OfficeDocumentProcessor aWordProcessor, OfficeRange aParagraphRange, int nCharIndex)
        {
            string strText = aParagraphRange.Text;
            int    nLength = (strText != null) ? strText.Length : 0;

            while ((nCharIndex < nLength) && (strText.IndexOfAny(m_achParagraphTerminators, nCharIndex, 1) == -1))
            {
                // get a copy of the range to work with
                OfficeRange aWordRange = Duplicate(aParagraphRange);

                // skip past initial spaces
                while ((nCharIndex < nLength) && (strText.IndexOfAny(m_achWhiteSpace, nCharIndex, 1) != -1))
                {
                    nCharIndex++;
                }

                // make sure we haven't hit the end of the paragraph (i.e. '\r') or range (beyond len)
                if (nCharIndex < nLength)
                {
                    if (strText.IndexOfAny(m_achParagraphTerminators, nCharIndex, 1) == -1)
                    {
                        // set the start index
                        aWordRange.StartIndex = nCharIndex;

                        // run through the characters in the word (i.e. until, space, NL, etc)
                        while ((nCharIndex < nLength) && (strText.IndexOfAny(m_achWordTerminators, nCharIndex, 1) == -1))
                        {
                            nCharIndex++;
                        }

                        // set the end of the range after the first space after the word (but not for NL)
                        if (++nCharIndex >= nLength)
                        {
                            --nCharIndex;
                        }

                        aWordRange.EndIndex = nCharIndex;

                        // make sure the word has text (sometimes it doesn't)
                        if (aWordRange.Text == null)                          // e.g. Figure "1" returns a null Text string
                        // if it does, see if it's "First Character" has any text (which it does in this case)
                        {
                            aWordRange.DealWithNullText();
                        }

                        // finally check it.
                        if (!aWordProcessor.Process(aWordRange, ref nCharIndex))
                        {
                            aWordProcessor.LeftOvers = aWordRange;
                            return(false);
                        }
                    }

                    strText = aParagraphRange.Text;                     // incase of replace, we've changed it.
                    nLength = (strText != null) ? strText.Length : 0;
                }
                else
                {
                    break;
                }
            }

            return(true);
        }
Example #7
0
		public override bool ProcessWordByWord(OfficeDocumentProcessor aWordProcessor)
		{
			if (aWordProcessor.AreLeftOvers)
			{
				DialogResult res = MessageBox.Show("Click 'Yes' to restart where you left off, 'No' to start over at the top, and 'Cancel' to quit", Connect.cstrCaption, MessageBoxButtons.YesNoCancel);
				if (res == DialogResult.No)
					aWordProcessor.LeftOvers = null;
				else if (res == DialogResult.Cancel)
					return true;
			}

			int nCharIndex = 0; // don't care
			foreach (Excel.Range aArea in Document.Areas)
			{
				foreach (Excel.Range aColumn in aArea.Columns)
				{
					if (aWordProcessor.AreLeftOvers && (aWordProcessor.LeftOvers.End > aColumn.Column))
						continue;

					foreach (Excel.Range aRow in aColumn.Rows)
					{
						if(     (aWordProcessor.AreLeftOvers && (aWordProcessor.LeftOvers.Start > aRow.Row))
							||  (String.IsNullOrEmpty((string)aRow.Text)))
							continue;

						ExcelRange aCellRange = new ExcelRange(aRow);
						aWordProcessor.LeftOvers = aCellRange;

						if (!aWordProcessor.Process(aCellRange, ref nCharIndex))
							return false;
					}

					aWordProcessor.LeftOvers = null;
				}
			}

			return true;
		}
		public override bool ProcessWordByWord(OfficeDocumentProcessor aWordProcessor)
		{
			if (Document.Selection.Type == Pub.PbSelectionType.pbSelectionNone)
				throw new ApplicationException("Nothing selected!");

			PubRange aSelectionRange = (PubRange)SelectionRange;
			PubParagraphs aParagraphs = aSelectionRange.Paragraphs;
			if (aParagraphs.Count > 1)
				return ProcessParagraphs(aWordProcessor, aParagraphs);
			else
			{
				int nCharIndex = 0;
				return aWordProcessor.Process(aSelectionRange, ref nCharIndex);
			}
		}
Example #9
0
		protected bool ProcessWholeRange(OfficeDocumentProcessor aWordProcessor, OfficeRange aParagraphRange, int nCharIndex)
		{
			string strText = aParagraphRange.Text;
			int nLength = (strText != null) ? strText.Length : 0;

			while ((nCharIndex < nLength) && (strText.IndexOfAny(m_achParagraphTerminators, nCharIndex, 1) == -1))
			{
				// get a copy of the range to work with
				OfficeRange aWordRange = Duplicate(aParagraphRange);

				// skip past initial spaces
				while ((nCharIndex < nLength) && (strText.IndexOfAny(m_achWhiteSpace, nCharIndex, 1) != -1))
					nCharIndex++;

				// make sure we haven't hit the end of the paragraph (i.e. '\r') or range (beyond len)
				if (nCharIndex < nLength)
				{
					if (strText.IndexOfAny(m_achParagraphTerminators, nCharIndex, 1) == -1)
					{
						// set the start index
						aWordRange.StartIndex = nCharIndex;

						// run through the characters in the word (i.e. until, space, NL, etc)
						while ((nCharIndex < nLength) && (strText.IndexOfAny(m_achWordTerminators, nCharIndex, 1) == -1))
							nCharIndex++;

						// set the end of the range after the first space after the word (but not for NL)
						if (++nCharIndex >= nLength)
							--nCharIndex;

						aWordRange.EndIndex = nCharIndex;

						// make sure the word has text (sometimes it doesn't)
						if (aWordRange.Text == null)  // e.g. Figure "1" returns a null Text string
							// if it does, see if it's "First Character" has any text (which it does in this case)
							aWordRange.DealWithNullText();

						// finally check it.
						if (!aWordProcessor.Process(aWordRange, ref nCharIndex))
						{
							aWordProcessor.LeftOvers = aWordRange;
							return false;
						}
					}

					strText = aParagraphRange.Text; // incase of replace, we've changed it.
					nLength = (strText != null) ? strText.Length : 0;
				}
				else
					break;
			}

			return true;
		}
		public bool ProcessWholeParagraphs(OfficeDocumentProcessor aWordProcessor, Word.Paragraphs aParagraphs)
		{
			foreach (Word.Paragraph aParagraph in aParagraphs)
			{
				// get the Range object for this paragraph
				Word.Range aParagraphRange = aParagraph.Range;

				// if we're picking up where we left off and we're not there yet...
				int nCharIndex = 0;
				if (aWordProcessor.AreLeftOvers)
				{
					if (aWordProcessor.LeftOvers.Start > aParagraphRange.End)
						continue;   // skip to the next paragraph

					nCharIndex = aWordProcessor.LeftOvers.StartIndex;
					aWordProcessor.LeftOvers = null; // turn off "left overs"
				}

				WordRange aRunRange = new WordRange(aParagraphRange);
				int nEndIndex = --aRunRange.EndIndex;
				int nLastIndex = nCharIndex;

				// exclude the paragraph end and process it as a whole unit (we may have to do this multiple times
				bool bStop = false;
				while (!bStop && (nCharIndex < nEndIndex))
				{
					aRunRange.StartIndex = nCharIndex;
					if (aRunRange.EndIndex != nEndIndex)
						aRunRange.EndIndex = nEndIndex;

					nLastIndex = nCharIndex;

					System.Diagnostics.Trace.WriteLine(String.Format("Start: {0}, End: {1}, text: {2}, length: {3}",
						aRunRange.Start, aRunRange.End, aRunRange.Text, aRunRange.Text.Length));

					if (!aWordProcessor.Process(aRunRange, ref nCharIndex))
					{
						aWordProcessor.LeftOvers = aRunRange;
						return false;
					}

					if (nLastIndex == nCharIndex)
						break;
				}
			}

			return true;
		}
		public bool ProcessParagraphsIsoFormat(OfficeDocumentProcessor aWordProcessor, Word.Paragraphs aParagraphs)
		{
			foreach (Word.Paragraph aParagraph in aParagraphs)
			{
				// get the Range object for this paragraph
				Word.Range aParagraphRange = aParagraph.Range;

				// if we're picking up where we left off and we're not there yet...
				int nCharIndex = 0;
				if (aWordProcessor.AreLeftOvers)
				{
					if (aWordProcessor.LeftOvers.Start > aParagraphRange.End)
						continue;   // skip to the next paragraph

					nCharIndex = aWordProcessor.LeftOvers.StartIndex;
					aWordProcessor.LeftOvers = null; // turn off "left overs"
				}

				WordRange aRunRange = new WordRange(aParagraphRange);
				int nStartIndex = aRunRange.StartIndex;
				System.Diagnostics.Debug.Assert(nStartIndex == 0);

				// if we have mixed character formatting, then use a binary search algorithm to find
				//	the maximum run.
				if (MixedCharacterFormatting(aRunRange))
				{
					int nWidth = aRunRange.EndIndex / 2;

					do
					{
						aRunRange.EndIndex++;

					} while (!MixedCharacterFormatting(aRunRange));

					aRunRange.EndIndex--;	// back up one
				}
				else
				{
					// the whole paragraph seems to be iso formatted, so exclude the paragraph end and
					// process it as a whole unit
					aRunRange.EndIndex--;
					if (!aWordProcessor.Process(aRunRange, ref nCharIndex))
					{
						aWordProcessor.LeftOvers = aRunRange;
						return false;
					}
				}
			}

			return true;
		}
Example #12
0
		public override bool ProcessWordByWord(OfficeDocumentProcessor aWordProcessor)
		{
			Document.MoveFirst();   // to avoid an error on the first 'Edit'
			int nDontCare = 0; // don't care
			while (!Document.EOF)
			{
				dao.Fields aFields = Document.Fields;
				dao.Field aField = aFields[m_strFieldName];
				if (aField.Value != System.DBNull.Value)
				{
					AccessRange aWordRange = new AccessRange(aField, this);

					try
					{
						if (!aWordProcessor.Process(aWordRange, ref nDontCare))
							return false;
					}
					catch (Exception)
					{
						throw;
					}
					finally
					{
						// this gets called whether we successfully process the word or not,
						//  whether we're returning 'false' (in the try) or not, and whether we
						//  have an exception or not... just exactly what we want, or MSAccess
						//  process won't release when we exit.
						OfficeApp.ReleaseComObject(aField);
						OfficeApp.ReleaseComObject(aFields);
					}
				}

				Document.MoveNext();
			}

			return true;
		}