I want to copy data from text file to word file. I already have tried it with different alternatives like string array, StringBuilder and StreamReader using Interop which works good, but it takes too much time. It would really be thankful if anyone can suggest me with a better one. Been through many forms on the web, but couldn't find.
FYI: My text file contains more than 1,00,000 lines.
This is one of which I have tried:
string[] lines = File.ReadAllLines(path); //path is text file path
var doc = new MSWord.Document();
foreach (string lin in lines)
{
doc.Content.Text += lin.ToString();
}
doc.Save();
Well, this works good but takes a lot of time and also sometimes throws an error like:
Unhandled Exception: System.Runtime.InteropServices.COMException: Word has encountered a problem.