none
How to read the text from a table which is in a header - (In VB Script) RRS feed

  • Question

  • Hi,

    I have Word documents, where I need to read the text which is in table cell and is in Header.

    1. How to read and print this text using vbscript

    2. Also there is an image in another cell of the same table under header, how to read the picture and print

    Thanks


    Mohan


    • Edited by JS Mohan Friday, June 5, 2015 4:42 PM
    Friday, June 5, 2015 4:41 PM

Answers

  • Hi JS

    2. I don't understand what you mean by "read the picture and print"?

    1. To access content in a table cell in a Header you do need to know in which section the Header can be found and whether it's a "normal" Header, a First Page header or an Even Page header. Assuming the default header (which would be in the first - and only - section):

    objDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1,1).Range.Text

    Note that, if you do NOT want the table structure escape codes appended to the end of the Text you need to cut off the last one, or two, characters. Whether one or two will depend on the version of Word involved, so you'll need to test what the code is returning. The end-of-cell characters are a combination of ANSI 13 & ANSI 7


    Cindy Meister, VSTO/Word MVP, my blog

    Saturday, June 6, 2015 6:49 PM
    Moderator
  • Hi JS

    Which version(s) of Word do you need to support? Most versions of Word have no functionality to save images in a document to disk. That's why I mentioned you'd need to copy it to the Clipboard and work from that. Although I don't know whether VB Script is able to read from the Clipboard...


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, June 9, 2015 4:19 PM
    Moderator

All replies

  • Hi JS

    2. I don't understand what you mean by "read the picture and print"?

    1. To access content in a table cell in a Header you do need to know in which section the Header can be found and whether it's a "normal" Header, a First Page header or an Even Page header. Assuming the default header (which would be in the first - and only - section):

    objDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1,1).Range.Text

    Note that, if you do NOT want the table structure escape codes appended to the end of the Text you need to cut off the last one, or two, characters. Whether one or two will depend on the version of Word involved, so you'll need to test what the code is returning. The end-of-cell characters are a combination of ANSI 13 & ANSI 7


    Cindy Meister, VSTO/Word MVP, my blog

    Saturday, June 6, 2015 6:49 PM
    Moderator
  • Thanks Cindy,

    There are some images in the table cell under header, i need to verify these images aganist the correct image in my d drive. I assume that i need to read the image and store in a variable then compare against the one in my d drive. but the code i have written is not working. Is this the correct approach or any other way i can verify this

    Thanks

    JS

    Sunday, June 7, 2015 9:44 AM
  • Hi JS

    What programming language are you using? Word's object model has nothing to support getting at the "insides" of a graphic file...

    You'll probably need to copy it to the Clipboard, then access the file from their, using tools available in the language you're working with.


    Cindy Meister, VSTO/Word MVP, my blog

    Sunday, June 7, 2015 7:14 PM
    Moderator
  • Iam using vbscript. I have identified image object as  objDoc.InlineShapes(1)

    But I am not finding a way to store this image into the local disk


    • Edited by JS Mohan Monday, June 8, 2015 3:49 PM
    Monday, June 8, 2015 3:34 PM
  • Hi JS

    Which version(s) of Word do you need to support? Most versions of Word have no functionality to save images in a document to disk. That's why I mentioned you'd need to copy it to the Clipboard and work from that. Although I don't know whether VB Script is able to read from the Clipboard...


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, June 9, 2015 4:19 PM
    Moderator
  • Here is a demo you can refer, it create a table with Pic inside in Word header.

    Set position of table in World Document as Outside 

    >>Read content 

    Get image

    int j = 1;
    foreach (Section sec in document.Sections)
    {
        foreach (Paragraph para in sec.Paragraphs)
        {
            List pictures = new List(); 
            foreach (DocumentObject docObj in para.ChildObjects)
            {
                if (docObj.DocumentObjectType == DocumentObjectType.Picture)
                {
                  //your code
                }
            }

    >>Print

    refer this article: Print a Word Document Programmatically in 5 steps.


    Friday, June 12, 2015 2:36 AM