In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains the "Asp.Net online preview Word document problem how to solve", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Asp.Net online preview Word document problem how to solve" it!
Project characteristics
Asp.Net is deployed on the Windows platform without Core,.NET Framework 4.0.
The general idea of the solution: first convert the Word document to Html, and then preview the Html. 1. Convert Word documents to Html
First quote Office's DLL, in COM, note: the computer needs to install Office.
Also note: please change the embedded interop type to False in the DLL attribute
There is one way to do the conversion process:
Using Microsoft.Office.Interop.Word;public static string WordToHtml (string path) {string root = AppDomain.CurrentDomain.BaseDirectory; var htmlName = $"{Guid.NewGuid (). ToString (" N ")} .html"; var htmlPath = root + $"Resource/Temporary/"; if (! Directory.Exists (htmlPath)) {Directory.CreateDirectory (htmlPath);} ApplicationClass word = new ApplicationClass () Type wordType = word.GetType (); Documents docs = word.Documents; Type docsType = docs.GetType (); Document doc = (Document) docsType.InvokeMember ("Open", BindingFlags.InvokeMethod, null, docs, new Object [] {(object) path, true, true}); Type docType = doc.GetType () DocType.InvokeMember ("SaveAs", BindingFlags.InvokeMethod, null, doc, new object [] {(htmlPath + htmlName), WdSaveFormat.wdFormatFilteredHTML}); docType.InvokeMember ("Close", BindingFlags.InvokeMethod, null, doc, null); wordType.InvokeMember ("Quit", BindingFlags.InvokeMethod, null, word, null); return htmlName;} 2, Preview
The method of converting Word to Html in the previous step is ready, and let's prepare such an Word document.
Write down the logic briefly:
Is it very simple? let's look at the effect of the finished product.
This solution has great limitations, and the deployment platform must be installed with Office, which is just what customers can meet.
Thank you for your reading, the above is the "Asp.Net online preview Word document problem how to solve" the content, after the study of this article, I believe you on the Asp.Net online preview Word document problem how to solve this problem has a deeper experience, the specific use of the situation also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.