C
C#2y ago
malkav

✅ Read or Store a new file .docx format with Microsoft.Office.Interop.Word

Does anyone know how to grab a string, and store it into a new file (.docx format) at a target location? I've got the "open docx" method:
private static string ReadDocx(string path)
{
Application app = new();
Document doc = app.Documents.Open(path);
StringBuilder sb = new();
for (int i = 0; i < doc.Words.Count; i++)
{
sb.Append(doc.Words[i].Text);
}

return sb.ToString();
}
private static string ReadDocx(string path)
{
Application app = new();
Document doc = app.Documents.Open(path);
StringBuilder sb = new();
for (int i = 0; i < doc.Words.Count; i++)
{
sb.Append(doc.Words[i].Text);
}

return sb.ToString();
}
but now I need the reverse, and I can't find a good source on how to do that. I am altering the result of this method into my own format, and now I have to create a new file
1 Reply
malkav
malkavOP2y ago
okay, rework of this post: The ReadDocx as written in the example above, it seems I am "missing file or assembly 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=xxxxxx'. Does this mean I have to have Office 2013 installed? Is there possibly another way of reading a docx file into a string?
Want results from more Discord servers?
Add your server