Insert data from the database into the word according to the table format in the word

now I need to insert some data from sqlserver into a word, I know how to use a bookmark, and the office api interface does it, but it slowly calls the word process, and this is the connection between the bookmark definition and the code, can this be done without starting the text process? If not, is there a template engine for this?

+4
source share
4 answers

You might want to take a look at the user documentation, rather than using the COM recruited API. I heard well about OfficeWriter. It's not free, but speed never happens.

It does not require Word on the server.

http://officewriter.softartisans.com/officewriter-59.aspx

0
source

I have no exact answer for what you want to do. However, you might consider creating an entire document on your server.

MS Excel 97 supports the creation of a simple XML or HTML file (with tables) and simply calls the something-uniqueid.xls file

It is possible that MS Word also does something similar. Take any basic HTML file (use the <h1> <h2> <u> tags to get started) and change the name to something.doc . See if Word opens it with a double click.

If this works, you can serve the entire document as an html file, but tell the client that it is called something-unique-id # .doc

To do this, to work from the web server, you will need to set the HTTP headers Content-type: application/msword and Content-disposition: Attachment; filename=something-unique-id.doc Content-disposition: Attachment; filename=something-unique-id.doc

Please check the MIME type for msword .. I'm not sure if this is correct.

Last but not least, to make sure to 100% try using URLs with the most recent GET variable set to .doc , this means your URL should look like /listing.asp?var1=abc&var2=def&output=.doc

This was necessary nine years ago to ensure 100% browser coverage. You will need to check is still required.

0
source

If you need this for Word 2003, why not just use WordML for this? Development with XML documents in Word

0
source

Not sure if this will help, but if it is tabular data from SQL Server, you may need to first transfer it to Excel (via the built-in query) and then insert the Excel spreadsheet into a Word document (OLE).

Sounds pretty clugy, but I did worse. :-)

-1
source

Source: https://habr.com/ru/post/1277009/


All Articles