none
Create word table in buffer RRS feed

  • Question

  • Hello,

    Currently I generate our Table of content by inserting a table in the document and then writing data row by row. It's very time consuming and sometimes word is not responding for large document.

    So is it possible to create table in buffer/memory and write data into it and after that show/insert this table in the document.

    Or is there any other way to create table with data and insert/add this table to the document in a single step.

    I use bookmarks to navigate document's table. I think it takes time to get particular range from bookmark.

     



    Monday, March 23, 2015 1:38 PM

Answers

  • ​Hi Saurabh,

    Could you share us how did you insert a table, by vba or vsto? I assume you used vsto.

    >> So is it possible to create table in buffer/memory and write data into it and after that show/insert this table in the document.

    As far as I know, if you used automating Word tables, it is impossible to achieve that, you need to create a table and then populate the table with data instead of inserting the table which already contains data. The link below shows the details.

    # Automating Word Tables for Data Insertion and Extraction
    https://msdn.microsoft.com/en-us/library/aa537149%28v=office.11%29.aspx?f=255&MSPPError=-2147217396

    Similar thread for your reference.
    https://social.msdn.microsoft.com/Forums/vstudio/en-US/5fe5a40f-d4be-49cf-9c4a-11a1d6d14f6f/how-to-bind-data-to-a-table-in-a-word-document?forum=vsto

    >> Or is there any other way to create table with data and insert/add this table to the document in a single step.

    I think you could try to use Open Xml SDK. The link below might be useful to you:

    # Increasing Word Automation Performance for Large Amounts of Data by Using Open XML SDK
    https://msdn.microsoft.com/en-us/library/office/ff191178(v=office.14).aspx

    In addition, if you have any issue about OpenXml, I will recommend you go to the link below for help.
    http://social.msdn.microsoft.com/Forums/en-US/home?forum=oxmlsdk

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, March 24, 2015 8:29 AM
  • Hi Saurabh,

    >>We are using bookmarks for each table to create hyperlink for Table of content.

    Is it a good way to navigate each table from table of content?

    Do you mean that you create bookmark for each table, and then loop the bookmark to navigate the each table? If so, I will recommend you use the Tables interface to loop the table.

    The Bookmark object is a member of the Bookmarks collection. The Bookmarks collection includes all the bookmarks listed in the Bookmark dialog box (Insert menu). When you loop the bookmarks, it will waste time on the bookmarks which are not the bookmarks for tables.

    The link below shows the details:

    #Bookmark interface
    https://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.bookmark.aspx

    The Tables interface is a collection of Table objects that represent the tables in a selection, range, or document. Use Tables(index), where index is the index number, to return a single Table object.

    The link below shows the details

    #Tables interface
    https://msdn.microsoft.com/en-us/library/Microsoft.Office.Interop.Word.Tables.aspx

    In addition, since your original issue is about “Create word table in buffer”. if you have any new topics to discuss about “Is it a good way to navigate each table from table of content?”, I will recommend you post a new thread.

    The reason why I suggested is:

    #1 There would be more community members to discuss the question.
    #2 For people who have the similar question, it would be easier for them to find the answer from a specific thread.

    Thanks for your understanding.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, March 26, 2015 9:34 AM

All replies

  • http://www.e-iceblue.com/Tutorials/Spire.Doc/Spire.Doc-Program-Guide/Table/How-to-Convert-Embedded-Excel-Sheet-to-Word-Table-in-C-VB.NET.html

    U can try this API, import data from data base then convert to doc:

    import data:

    //Create a new workbook
    Workbook workbook = new Workbook();       
    //Load a file and imports its data
    workbook.LoadFromFile(@”..\FandH.xlsx”);          
    //Initialize worksheet
    Worksheet sheet = workbook.Worksheets[0];
    // get the data source that the grid is displaying data for
    this.dataGridView1.DataSource = sheet.ExportDataTable()

    convert:

    foreach (DocumentObject obj in para.ChildObjects)
    {
        if (DocumentObjectType.OleObject == obj.DocumentObjectType)
        {
            DocOleObject dObj = obj as DocOleObject;
            if (dObj.ObjectType == "Excel.Sheet.12")
            {
                Workbook wb = new Workbook();
                wb.LoadFromStream(new MemoryStream(dObj.NativeData));
                Worksheet ws = wb.Worksheets[0];
                dt = ws.ExportDataTable(ws.AllocatedRange, false);
            }
        }
    }

    Tuesday, March 24, 2015 3:49 AM
  • ​Hi Saurabh,

    Could you share us how did you insert a table, by vba or vsto? I assume you used vsto.

    >> So is it possible to create table in buffer/memory and write data into it and after that show/insert this table in the document.

    As far as I know, if you used automating Word tables, it is impossible to achieve that, you need to create a table and then populate the table with data instead of inserting the table which already contains data. The link below shows the details.

    # Automating Word Tables for Data Insertion and Extraction
    https://msdn.microsoft.com/en-us/library/aa537149%28v=office.11%29.aspx?f=255&MSPPError=-2147217396

    Similar thread for your reference.
    https://social.msdn.microsoft.com/Forums/vstudio/en-US/5fe5a40f-d4be-49cf-9c4a-11a1d6d14f6f/how-to-bind-data-to-a-table-in-a-word-document?forum=vsto

    >> Or is there any other way to create table with data and insert/add this table to the document in a single step.

    I think you could try to use Open Xml SDK. The link below might be useful to you:

    # Increasing Word Automation Performance for Large Amounts of Data by Using Open XML SDK
    https://msdn.microsoft.com/en-us/library/office/ff191178(v=office.14).aspx

    In addition, if you have any issue about OpenXml, I will recommend you go to the link below for help.
    http://social.msdn.microsoft.com/Forums/en-US/home?forum=oxmlsdk

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, March 24, 2015 8:29 AM
  • I'm using VSTO and use the following code to insert a table:

    document.Tables.Add(tableLocation, 3, 4);

    We are using bookmarks for each table to create hyperlink for Table of content.

    Is it a good way to navigate each table from table of content?

    Thanks,

    Saurabh

    Tuesday, March 24, 2015 2:19 PM
  • Hi Saurabh,

    >>We are using bookmarks for each table to create hyperlink for Table of content.

    Is it a good way to navigate each table from table of content?

    Do you mean that you create bookmark for each table, and then loop the bookmark to navigate the each table? If so, I will recommend you use the Tables interface to loop the table.

    The Bookmark object is a member of the Bookmarks collection. The Bookmarks collection includes all the bookmarks listed in the Bookmark dialog box (Insert menu). When you loop the bookmarks, it will waste time on the bookmarks which are not the bookmarks for tables.

    The link below shows the details:

    #Bookmark interface
    https://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.bookmark.aspx

    The Tables interface is a collection of Table objects that represent the tables in a selection, range, or document. Use Tables(index), where index is the index number, to return a single Table object.

    The link below shows the details

    #Tables interface
    https://msdn.microsoft.com/en-us/library/Microsoft.Office.Interop.Word.Tables.aspx

    In addition, since your original issue is about “Create word table in buffer”. if you have any new topics to discuss about “Is it a good way to navigate each table from table of content?”, I will recommend you post a new thread.

    The reason why I suggested is:

    #1 There would be more community members to discuss the question.
    #2 For people who have the similar question, it would be easier for them to find the answer from a specific thread.

    Thanks for your understanding.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, March 26, 2015 9:34 AM