1、Duck

可以提取word的内容与表格,新建工程直接复制源码就可以得到库

 

使用实例如下所示:

using namespace duckx;
    duckx::Document doc("file.docx");
    doc.open();
    
    //获取当前word中所有的表格
    for (auto p = doc.tables(); p.has_next(); p.next())
    {
        //获取所有行
        for (auto r = p.rows(); r.has_next(); r.next())
        {
            //获取所有列的数据
            for (auto r1 = r.cells(); r1.has_next(); r1.next())
            {
                for (auto r2 = r1.paragraphs(); r2.has_next(); r2.next())
                {
                    for (auto r3 = r2.runs(); r3.has_next(); r3.next())
                    {
                        std::string strText = r3.get_text();
                        std::string str1 = UTF8ToGB2312(strText);
                        int yy = 55;
                    }
                }
            }
        }
    }
    //读取当前word里面普通的内容
    for (auto _doc = doc.paragraphs(); _doc.has_next(); _doc.next())
    {
        for (auto r = _doc.runs(); r.has_next(); r.next())
        {
            std::string strText = r.get_text();
            std::string str1 = UTF8ToGB2312(strText);
            int yy = 55;
        }
    }

2、DocxFactory 对于doc模板操作比较合适

可以下下载相关的头文件,lib库以及dll文件

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐