最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why is docx library generating invalid doc file when creating a different copy of the node? - Stack Overflow

programmeradmin0浏览0评论

I am trying to build a library using docx. And I wanted to implement plugin architecture. So, the data provided by plugin should work well with the eco-system.

But strangely, when I compare the data with JSON.stringify, the same data when created directly using docx library instance in the app works but the same data geenrated in some other library using the docx library does not work.

Initially I had no clue. But I just tested out this

// this is the simplified code
new Documnet({
   sections: [
    children: {
       Object.assign({}, new Paragraph("some text"));
    }
  ]
})

If you don't use Object.assign, it works well. But it created corrupted document when I used Object.assign.

When I compared the working and non-working files, I noted that the corrupt file had <rootKey>w:r</rootKey> in document.xml in place of <w:r><w:t xml:space="preserve">some text here</w:t></w:r>.

Also check out this issue -

I tried going through the codebase but didn't find any obvious reason. Can anyone help with this please.

Here's the exact code - .ts#L106

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论