Docx-templates (Word web mailmerge): will this work with NetTalk?

Hi all,

In our Clarion for Windows application we have the ability that users can merge Word documents (docx) with {merge} fields, for example:
Hello {Name}

I am looking for a web solution and found this great tool: docx-templates:

Demo:
https://codesandbox.io/p/sandbox/docx-templates-demo-26k0m

This tool will parse an existing docx file and merge it with for example json data. And saves the merged document (result) as a new docx file which can be downloaded. It has a lot of nice and powerful options, like insert table data, images (qr), etc.

I have downloaded the source.zip but I see all kind of .ts files (TypeScript). So no JavaScript.

My question is: Can this tool be implemented in a NetTalk Web project? That would be very cool!! A complete web mail merge solution!

See also:

Best regards
Jeffrey

Hi Jeffrey,

I don’t know enough about the repo, but you maybe able to implement docx-templates in a NetTalk Web project, but since it’s written in TypeScript (TS), you’ll need to transpile it into JavaScript (JS) first. Tools like Visual Studio Code with TypeScript extensions make this process simple. Once installed, you can use the TypeScript compiler (tsc) to convert the .ts files into .js files.

NetTalk allows you to call JavaScript functions directly from your web application, so once the TypeScript code is transpiled into JavaScript, you can integrate the resulting .js files into your project and call the functions as needed. (A hole other topic)

Here’s a helpful link to get started with TypeScript: TypeScript Handbook.

It’s not something I have tried, but you might be able to get it to work for you.

Best regards,
Mark

Thank you Mark for the helpful info.

Best regards
Jeffrey

They also talk about using Node.js. I wonder if NetTalk supports this.

Best regards
Jeffrey

Hi Jeffrey,

I hadn’t studied the repo in detail but noticed it’s TypeScript-based. If Node.js is required (which appears to be the case for docx-templates), you could create a Node.js server app acting as an API. This API could run on a different port or be hosted separately. Your NetTalk Web Server would send a request to the API and consume the returned result.

It’s definitely doable, though it would introduce you to some new technologies in the process, If you’re up for the challenge.

Mark

Hi Mark,

Interesting, I just found this helpful article:

JavaScript Create Document From Template with Docx-Templates:

Best regards
Jeffrey

Thats not entirely accurate. NetTalk doesnt “call” JavaScript, because JavaScript is a client-side language not a server language.

It does allow you to "tell the client to run this JavaScript ". But ot doesnt “call” the JavaScript.

Thats not entirely accurate. NetTalk doesnt “call” JavaScript, because JavaScript is a client-side language not a server language.

It does allow you to "tell the client to run this JavaScript ". But ot doesnt “call” the JavaScript.

I have developed a similar solution with office inside long ago. With the same logic for excel and word too. I have even developed the template that extract info from cpcs reports and creates excel output on the fly. At the time I struggled to explain the idea to my boss so I took the liberty to do it quickly , while he was 3 days on vacation :slight_smile:

I have embedded in the excel “template” also some logic for filtering and totaling.
It was fun and I repeated the same idea in c# and php for some other projects.

Imagine that you have a special sheet where you format excel cells. For example bold, underline, number format.

Then runtime you parse the template sheet and fill a report sheet and it retains the formatting

After filling the report sheet you can remove the template sheet. The logic is same for word.
Everything doable with office inside.

And doable also with php so web solution.

But you are talking about nettalk web solution.Since this will be hosted locally by you I suppose it is no problem to create a c# project that will open a tcp socket where your nettalk web will send info what to merge and how. Never done nettalk web but nettalk yes and I suppose you can open from nettalk web a socket to your local server.

hth
Nenad

Hi Nenad,

That’s a nice solution for your project.

I’m looking for a pure Web solution and docx-templates could be the solution if I can make it work with NetTalk. There’s no MS Word at server side, so we can’t use CS Office Inside, which would be a too heavy server load btw.

Best regards
Jeffrey

I checked my old project. EPPlus, the lib I used in the C# version of my projects does not require office to be installed. This should be the last free version GitHub - JanKallman/EPPlus: Create advanced Excel spreadsheets using .NET

I see they now have a commercial product with these prices License and pricing - EPPlus Software

For simple merge, you can do this:

  • unzip “your.docx” file into some folder , ie: c:\yourfolder (it is basically ZIP file)
  • load “document.xml” file from c:\yourfolder\word\document.xml
  • do search and replace (in you case, search for Hello {Name} and replace it with Hello whatever (or replace just {Name}
  • save xml file (into same place)
  • delete original “your.docx”
  • zip content of c:\yourfolder folder into “your.docx” (in the original location of your.docx)

Hi Jeffrey,

My program heavily uses merging Html and Rtf for resp. E-mails and letters. The Html templates with merge tokens are made with a stand alone editor (window forms Text Control). The Rtf templates with merge tokens are made with a stand alone version of MS Word, merged and opened in the same Ms Word before printing. I first tried it with the Clarion rtf editor (available in Anyscreen) but it doesn’t allow columns which i need for ie invoice line items.

I asked Marko Golem if i can use the same technique in a AnyScreen App? Or do i need a server side editor like Word 365 or …?

He answerd:
You can use javascript object which can hold any html / javascript page. You can check provided AnyScreen demo application in your clarion examples folder.

Didn’t try it yet. So i am as far as you are:)

Maybe this is a solution:

Thank you all!

I will first try docx-templates, see my first post. This has all the great functionality which I need.

I have to figure out how to use this in a NetTalk Web application.

Best regards
Jeffrey