Jump to content
viSci

Create table in active word document

Recommended Posts

I would like to obtain a .net reference to an open word document and add a table at the current cursor location in the document.  I can already do this using a crude

automated copy and paste method but would like to be able to add a proper word table into the document.  Using the .net interfaces I think this is possible but so far

have not been able to get it to work.  Has anyone tried to do this before? 

Share this post


Link to post
Share on other sites

I was under the impression that the .net interfaces just wrapped the old activex interfaces. Is that wrong?

to actually answer your question I've never used it, but it seems like these might work:

text ("TextType" section halfway down): https://docs.microsoft.com/en-us/visualstudio/vsto/how-to-programmatically-insert-text-into-word-documents?view=vs-2017

table: https://docs.microsoft.com/en-us/visualstudio/vsto/how-to-programmatically-create-word-tables?view=vs-2017

If I'm reading the samples right it looks like you can get the current cursor from "Application.Selection" and then insert a table using a method on that object.

Share this post


Link to post
Share on other sites

Thanks - I was able to use your suggestion to get the current cursor position and it worked correctly.  I was able to construct and insert a proper table in an open word document. 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.