Мне нужно открыть файл .mht в документе OpenXml и файл SaveAs .docx программно на C#.
Я добился этого с помощью библиотеки Microsoft.Office.Interop.Word, используя приведенный ниже C#. . Здесь я создаю файл .mht, записываю содержимое .mht в word и сохраняю его как «SaveAs» в docx.
Однако мне нужно добиться этого с помощью OpenXml.
Цель состоит в том, чтобы файл .mht открывался в документе так же, как веб-страница.
если это неправильно, есть ли другой способ добиться этого? пожалуйста, помогите мне. спасибо
var fileNameForMht ="test.mht";
string path = Path.Combine(PathName, fileNameForMht);
string outPath= Path.Combine(PathName, FileName);
Application wordApp = new Application();
Microsoft.Office.Interop.Word.Document doc = null;
// Create the blank mht file, or overwrite if the file exists.
using (FileStream fs = File.Create(path))
{
fs.Close();
}
// write the mht content to mht file created above.
File.WriteAllText(path, htmlContent); // htmlContent have the content of mht file
//Opens the specified mht document
doc = wordApp.Documents.Open(path);
// saves the mht document as word format.
doc.SaveAs2(outPath, WdSaveFormat.wdFormatXMLDocument);
Подробнее здесь: https://stackoverflow.com/questions/790 ... ml-c-sharp