Load text file into table - Documents for Word .NET

Posted by: remus.iftimie on 9 July 2020, 11:25 pm EST

    • Post Options:
    • Link

    Posted 9 July 2020, 11:25 pm EST

    Load a text file that have values separated by # character (similar to a CSV file) into a table. The text file contains about 50 columns and I want to load only 7 columns from it into the new table (that will have only 7 columns). And to save the output as a .docx file.

  • Posted 12 July 2020, 2:43 pm EST

    Hi Remus,

    You can use the code snippet given below to save the data from the text file into the array so that you save load it into the table:

    String input = File.ReadAllText(@"Data.txt");
    int i = 0, j = 0;
    var rows = input.Split('\n');
    string[,] result = new string[rows.Count(), 7];
    foreach (var row in rows)
      j = 0;
      foreach (var col in row.Trim().Split('#'))
          if (j < 7)
            result[i, j] = col.Trim(new char[] { '"'});

    Please go through the following link to learn how to create the table in the word file via code:


    If you need any other help, please let us know.


    Prabhat Sharma.

  • Posted 13 July 2020, 2:55 am EST

    Thank you for the solution !

  • Posted 13 July 2020, 2:56 am EST

    Thank you for the solution !

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels