Ahoj.
Kdybys chtěl, udělal jsem jednoduchou konzolovou apku pro Win, pomocí které to můžeš jednoduše zautomatizovat.
Syntaxe je tato:
txtToWord2.exe lpt1.txt nazevWord.docx
using Word = Microsoft.Office.Interop.Word;
class Program
{
static void Main(string[] args)
{
if (args.Length == 0)
{
System.Console.WriteLine("Please enter an argument.");
return;
}
if (args.Length != 2)
{
System.Console.WriteLine("Spatny pocet parametru.");
}
Word.Application wordApp = new Word.Application();
Word.Document wordDoc = wordApp.Documents.Add();
System.Console.WriteLine(args[0].ToString());
System.Console.WriteLine(args[1].ToString());
System.Console.WriteLine("Starting...");
StringBuilder stringBuilder = new StringBuilder();
using (FileStream fs = File.Open(args[0].ToString(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (BufferedStream bs = new BufferedStream(fs))
using (StreamReader sr = new StreamReader(bs))
{
wordDoc.Content.Text = sr.ReadToEnd();
wordDoc.Sections[wordDoc.Sections.Count].PageSetup.Orientation = Word.WdOrientation.wdOrientLandscape;
wordDoc.SaveAs(AppDomain.CurrentDomain.BaseDirectory + "//" + args[1].ToString());
}
System.Console.WriteLine("Complete");
wordDoc.Close();
}
}
Přeložený program pro konzoli je rovnou v příloze.