Giter Site home page Giter Site logo

totravel / minidocx Goto Github PK

View Code? Open in Web Editor NEW
57.0 1.0 19.0 277 KB

C++ library for creating Microsoft Word Document (.docx). 用于创建 Microsoft Word 文档的 C++ 类库

License: MIT License

CMake 2.37% Shell 1.02% C++ 96.62%
docx word ooxml office

minidocx's People

Contributors

germanaizek avatar totravel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

minidocx's Issues

How to convert .doc to .docx?

@totravel,
Is there conversion library function? Maybe it's about WinAPI, but I'm not sure. The situation is this: user can specify (.doc, .docx) files, parser is only .docx

<algorithm> not included

Hi, I'm writing bindings of minidocx for the Nim programming language and got an error in minidocx.cpp since it couldn't find std::find, and it seems I needed to #include <algorithm>.
I'm not sure if this is an actual error of minidocx or if it has something to do with my computer.

libreoffice 打开失败

想法不错,期待这个minidocx。
测试用例里面生成的docx文件,mac os 自带的pages打开没有问题,但是LibreOffice打开失败

希望有可能表格和图片功能

How to open not exist document?

@totravel,

Example:

bool Document::Open(const std::string& path, bool createIfNotExist = false)
docx::Document doc;
doc->Open(path, true);

or C file functions be like

doc->Open(path, 'r');
doc->Open(path, 'w');
doc->Open(path, 'w+');
doc->Open(path, 'a');
doc->Open(path, 'rb');

support table

请问什么时候支持表格、图片等内容的写入呢

Separate new method for manage document path

@totravel,
it may be worth adding separate SetPath(const std::string& path) method that only sets path from parameter function. Because in my code I made in class private member docx::Document*. I have constructor class working on creating an object document, but there is no way to reassigning path.

请问如何输入 tab 控制符

输入 tab 是用来对齐用的,代码如下:

auto p = doc.AppendParagraph("甲 方:\t\t\t\t乙 方:", 12, "Times New Roman", "宋体");

以上的 \t 并不起作用,生成的文件中被替换成了空格,请教应如何输入 tab 控制符

How to find any Word objects

@totravel, many thanks and hello again.
How to find Word objects and return their, to then insert/replace before/after it and edit object properties.

Example:

  • GetWordImageItem (find and return object Image)
  • GetWordTableItem (find and return object Table)
  • etc ...
auto text = GetWordTextItem("TEXT FOR SEARCH");
text.SetText("NEW VALUE");

or

GetWordTextItem(string or formula or id element or xml node)

How to set new value finded node

Example:

for (pugi::xml_node i = impl_->w_body_.first_child(); i; i = i.next_sibling()) {
      if (std::strcmp(i.name(), "w:p") != 0) continue;

      for (pugi::xml_node j = i.first_child(); j; j = j.next_sibling()) {

        if (std::strcmp(j.name(), "w:r") == 0) {

          for (pugi::xml_node k = j.first_child(); k; k = k.next_sibling()) {

            if (std::strcmp(k.name(), "w:t") == 0) {
                  k.value = "new value";
            }
          }
      }
}

添加富文本或段落中的 '\n' 换行无法添加进 Word 文档中

问题描述

使用 AppendParagraph 或 AppendRun 函数向文本中添加的 '\n' 换行无法添加到 Word 文档中,只能调用 AppendLineBreak 函数手动添加换行。

期望结果

AppendParagraph 和 AppendRun 函数能够将字符串中的 '\n' 换行添加到 Word 文档中。

示例代码

#include "minidocx.hpp"
using namespace docx;

int main()
{
    Document doc("Test.docx");
    auto p = doc.AppendParagraph("This is first line. \n This is second line.", 16);
    doc.Save();
    return 0;
}

编译环境

  • Windows 环境
    • Windows 11
    • g++ 8.1.0
    • 使用 WPS 阅读 Word
  • Linux 环境
    • Linux Mint 21.2
    • g++ 11.4.0
    • 使用 LibreOffice 阅读 Word

生成结果

image

Advanced functionality for working with bookmarks

@totravel, it would be really convenient to work with bookmarks if there were these functions.

/**
    * Compare bookmarks.
    * @param name1 Name first bookmark.
    * @param name2 Name second bookmark.
    * @return enum
    * 0 Bookmarks match.
    * 1 The first bookmark is located below the second one and does not intersect it.
    * 2 The first tab is above the second one and does not intersect it.
    * 3 The first bookmark is located below the second one and crosses it.
    * 4 The first tab is above the second one and crosses it.
    * 5 The first bookmark includes the second one.
    * 6 The second bookmark includes the first one.
    * 7 Bookmarks start in one place, but the first one is longer.
    * 8 Bookmarks start in one place, but the second one is longer.
    * 9 Bookmarks end in one place, but the first one is longer.
    * 10 Bookmarks end in one place, but the second one is longer.
    * 11 Bookmarks are next to each other and the first one is below the second one.
    * 12 Bookmarks are located next to each other and the first one is higher than the second one.
    * 13 One of the bookmarks does not exist.
    */
   int CmpBookmarks(std::string name1, std::string name2);
/**
 * Checking the existence of a bookmark.
 * @param name Name bookmark.
 * @return bool true if bookmark exists, false otherwise.
 */
bool ExistingBookmark(std::string name);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.