請高手指教,菜鳥一個,謝謝了!1!!
uj5u.com熱心網友回復:
這要用word自帶的庫,先import或者用vs匯入進來。具體思路,現在word中利用vba宏生成vba代碼,然后參考vba代碼,從庫中匯入相應的類,然后再實作你的功能。
下面的代碼希望能幫到你,m_WordDoc是代表你一個document的物件,先獲取分節符集,然后獲取分節符,然后再從每個分節符中獲取頁腳和頁眉。
CSections sections;
sections.AttachDispatch(m_WordDoc.get_Sections());
if(sections.m_lpDispatch == nullptr)
return TCHandleResult(TC_FAILED, _T("獲取分節符集失敗"));
long lSectionNum = sections.get_Count();
for (long i = 0; i < lSectionNum; i++)
{
CSection section;
CHeadersFooters headersFooters;
section.AttachDispatch(sections.Item(i+1));
if (section.m_lpDispatch == nullptr)
continue;
headersFooters.AttachDispatch(section.get_Footers());
if (headersFooters.m_lpDispatch == nullptr)
continue;
long sFooterCount = headersFooters.get_Count();
for (long j = 0; j < sFooterCount; j++)
{
CHeaderFooter headerFooter;
headerFooter.AttachDispatch(headersFooters.Item(j+1));
if (headerFooter.m_lpDispatch == nullptr)
continue;
CRange range = headerFooter.get_Range();
if (range.m_lpDispatch == NULL)
return TCHandleResult(TC_FAILED, _T("獲取頁腳頁眉的range物件失敗"));
CString sText = range.get_Text();
CTables0 tables = range.get_Tables();
if ((sText.GetLength() < 5) && (0 == tables.get_Count()))//剔除頁腳頁眉為慷訓者只有頁碼的情況
continue;
}
headersFooters.AttachDispatch(section.get_Headers());
if (headersFooters.m_lpDispatch == nullptr)
continue;
sFooterCount = headersFooters.get_Count();
for (long j = 0; j < sFooterCount; j++)
{
CHeaderFooter headerFooter;
headerFooter.AttachDispatch(headersFooters.Item(j + 1));
if (headerFooter.m_lpDispatch == nullptr)
continue;
CRange range = headerFooter.get_Range();
if (range.m_lpDispatch == NULL)
return TCHandleResult(TC_FAILED, _T("獲取頁腳頁眉的range物件失敗"));
CString sText = range.get_Text();
CTables0 tables = range.get_Tables();
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/59744.html
上一篇:初學網路編程需要看那些書?
下一篇:默認path環境變數
