M
mjlaali
I am developing a word automation application. In a method of mine, I change
the text of some sentences of an opened word file, but the problem is when I
change the text of a sentence which located before a table, it will be moved
to the first cell of the table. My code is as follow:
void myMethod( long startingSentenceNumber, const char *toBeSearched, const
char *replacement, bool replace )
{
Range currentSentenceRange;
Selection sentenceSelection;
Sentences sentencesList = m_document.GetSentences();
long sentencesCount = sentencesList.GetCount();
CString replacementCStr(replacement);
for (long newIndex = startingSentenceNumber; newIndex <= sentencesCount;
newIndex++)
{
currentSentenceRange = sentencesList.Item(newIndex);
CString currentSentenceText = currentSentenceRange.GetText();
const char *temp = currentSentenceText;
std::string currentString(temp);
std::string toBeSearchedString(toBeSearched);
if (/*some condition*/)
{
std::string endCharacters = currentString.substr(strlen(toBeSearched),
currentString.size() - strlen(toBeSearched));
replacementCStr += endCharacters.c_str();
if (replace)
{
currentSentenceRange.SetText(replacementCStr);
}
foundedSentenceIndex = newIndex;
break;
}
currentSentenceRange.ReleaseDispatch();
sentenceSelection.ReleaseDispatch();
}
sentencesList.ReleaseDispatch();
}
How could I solve this problem?
the text of some sentences of an opened word file, but the problem is when I
change the text of a sentence which located before a table, it will be moved
to the first cell of the table. My code is as follow:
void myMethod( long startingSentenceNumber, const char *toBeSearched, const
char *replacement, bool replace )
{
Range currentSentenceRange;
Selection sentenceSelection;
Sentences sentencesList = m_document.GetSentences();
long sentencesCount = sentencesList.GetCount();
CString replacementCStr(replacement);
for (long newIndex = startingSentenceNumber; newIndex <= sentencesCount;
newIndex++)
{
currentSentenceRange = sentencesList.Item(newIndex);
CString currentSentenceText = currentSentenceRange.GetText();
const char *temp = currentSentenceText;
std::string currentString(temp);
std::string toBeSearchedString(toBeSearched);
if (/*some condition*/)
{
std::string endCharacters = currentString.substr(strlen(toBeSearched),
currentString.size() - strlen(toBeSearched));
replacementCStr += endCharacters.c_str();
if (replace)
{
currentSentenceRange.SetText(replacementCStr);
}
foundedSentenceIndex = newIndex;
break;
}
currentSentenceRange.ReleaseDispatch();
sentenceSelection.ReleaseDispatch();
}
sentencesList.ReleaseDispatch();
}
How could I solve this problem?