C# word生成html

引入 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的格式或版本不适用");
            }
        }

 

posted @ 2019-01-08 14:53  生命不息bug不止  阅读(724)  评论(0编辑  收藏  举报