Jump to content

Create table in active word document


viSci

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? 

Link to comment

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.

Link to comment

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.