Insert Footer for a Word Doc from T-SQL

  • Hi There

    I need to know that, is there any way to insert a text from a variable for a formatted word document from a SQL Procedure? If so please help me out in finding a solution for that.

    Cheers

    JB

  • you'd need to use Word Automation, where you open the word document programatically, change the header and footer, and save it.

    TSQL is the wrong tool for that, like cutting boards with a hammer; you might get it done, but you will not like the look of the results.

    that has to be done in a programming language; you'd probably want to create a program to do it, whether a console application or a dll.

    then you could probably find a clutzy way to call that program or dll via TSQL.

    So, it really cannot be done from within TSQL, or at least without all the hard work being done elsewhere, and then calling a streamlined process to do it in TSQL. then you could use the "hammer" (TSQL) to turn on the saw(.NET), so to speak.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thanks Lowell for your headsup, but thats my limitation.

    Actually to explain more on my need, it is that, there will be a template in a designated folder and according to the data, a procedure process will copy the document to another directory and it should also update some data into the footer area of the document. this whole process wont have any interface like .net or so involved. :(.

    Anyway... Thanks for your suggestion.

  • if your template has a keyword you could search for, like a token of "[footer]" that you could search for and find/replace as a raw text string, that might be an option;

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Yes, The template has the keyword, but how to update the value to a word footer? can you suggest me a sample with syntax?

  • i just tested it, and it would not work; created a word doc with "[header]" in the header,"[footer]" in the footer, and "[body]" in the main document;

    saved it and then opened it in a raw text editor;

    i could replace "[footer]" with"[banana]" but not with any string that was shorter or longer than the string.

    I'm sorry, that's just not going to work, unless it's padded with a ton of spaces, and you only swap out spaces for text; if you needed formatting on the string, like bold,italics/font sizes, that will not be possible either, at least with string replacement.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • You should try looking into "Mail Merge" for Word documents. This feature is probably what you want to employ to go about doing this kind of a thing.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply