N
N
Nadim Zakirov2021-01-07 14:48:29
JavaScript
Nadim Zakirov, 2021-01-07 14:48:29

How to edit .doc with JavaScipt?

I created a template in the outdated .doc format and introduced markers like this: {name} {date} , etc.

Can these markers now be programmatically replaced with something of my own? Right in the browser, without involving the server.

spoiler
Попробовал открыть .doc как zip-архив и он даже открылся, но кроме некоторых служебных xml-файлов ничего внутри не нашел, т. е. текста документа в самом архиве нет, видимо он зашифрован как-то в теле документа, вопрос лишь в том, как?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
N
Nadim Zakirov, 2021-01-08
@zkrvndm

I found a way to do text replacement in a .doc format document.
The bottom line is that if we open .doc as plain text, we will see only crocozyabrs, but this does NOT apply to macro code, if they (macros) are of course in the document. Accordingly, we write a self-starting macro for auto replacement using our markers, and then we stupidly replace these markers with the data we need.
The only minus here is that all markers must be of a fixed length, i.e., after editing, the length of the document should not change, but this limitation is easily circumvented by adding spaces.
PS In JavaScript, you cannot edit a .doc file as a string, it gets corrupted by this, but you can overtake it in Uint8Arrayand work with him.

D
d-stream, 2021-01-07
@d-stream

Now it remains to introduce a macro into this template, which will do the replacement and pull it programmatically.

A
Artur, 2021-01-07
@artur_kudaev

Nodejs

R
Ranwise, 2021-01-07
@Ranwise

Nadim Zakirov - find docx specifications and write xml parser

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question