C# word生成html

邮差的信 提交于 2020-12-17 21:42:31

引入 Aspose.Words

public void ConvertToHtml(string wordPath, string savaPath)
        {
            try
            {
                Aspose.Words.Document doc = new Aspose.Words.Document(wordPath);

                if (doc == null)
                {
                    throw new Exception("Word文件无效或者Word文件被加密!");
                }

                if (savaPath.Trim().Length == 0)
                {
                    savaPath= Path.GetDirectoryName(wordPath);
                }

                if (!Directory.Exists(savaPath))
                {
                    Directory.CreateDirectory(savaPath);
                }

                string wordName = Path.GetFileNameWithoutExtension(wordPath);
                Aspose.Words.Saving.HtmlSaveOptions htmlSaveOptions = new Aspose.Words.Saving.HtmlSaveOptions(Aspose.Words.SaveFormat.Html);
                string wordPath = Path.Combine(savaPath, wordName ) + "_001.html";
                doc.Save(wordPath , htmlSaveOptions);
            }
            catch (Exception ex)
            {
                throw new FriendlyException("word的格式或版本不适用");
            }
        }

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!