OpenXmlPowerTools.HtmlConverter.ConvertToHtml()将项目符号转换为?(问号)

时间:2016-12-13 12:55:07

标签: c# asp.net openxml

在我的网站上,客户端可以导入word文件。我正在将这个word文件转换为html。

  

我面临的问题是返回的html是否正在返回?为了   无序的子弹。

作为测试,我检查了从内存流重新创建.docx文件,这里没有问题。

        try
        {

            var fi = new FileInfo(filePath + "/" + fileName);
            string outputDirectory = filePath.Replace("ImportFiles", "XmlFiles");
            byte[] byteArray = File.ReadAllBytes(fi.FullName);
            using (MemoryStream memoryStream = new MemoryStream())
            {
                memoryStream.Write(byteArray, 0, byteArray.Length);
                using (WordprocessingDocument wDoc = WordprocessingDocument.Open(memoryStream, true))
                {
                    var destFileName = new FileInfo(fi.Name.Replace(".docx", ".xml"));
                    if (outputDirectory != null && outputDirectory != string.Empty)
                    {
                        DirectoryInfo di = new DirectoryInfo(outputDirectory);
                        if (!di.Exists)
                        {
                            throw new OpenXmlPowerTools.OpenXmlPowerToolsException("Output directory does not exist");
                        }
                        destFileName = new FileInfo(Path.Combine(di.FullName, destFileName.Name));
                    }
                    var imageDirectoryName = destFileName.FullName.Substring(0, destFileName.FullName.Length - 5) + "_files";
                    int imageCounter = 0;
                    string imageFileName = "", resourceFileName ="";
                    var pageTitle = (string)wDoc.CoreFilePropertiesPart.GetXDocument().Descendants(DC.title).FirstOrDefault();
                    if (pageTitle == null)
                        pageTitle = fi.FullName;
                    imageDirectoryName = AppDomain.CurrentDomain.BaseDirectory + "Temp";
                    HtmlConverterSettings settings = new HtmlConverterSettings()
                    {
                        PageTitle = pageTitle,
                        FabricateCssClasses = true,
                        CssClassPrefix = "pt-",
                        RestrictToSupportedLanguages = false,
                        RestrictToSupportedNumberingFormats = false,
                     }
                    XElement html = OpenXmlPowerTools.HtmlConverter.ConvertToHtml(wDoc, settings);



                    var htmlString = html.ToString(SaveOptions.DisableFormatting);
                    File.WriteAllText(destFileName.FullName, htmlString, Encoding.UTF8);
                    string bodyContent = GetBodyContent(htmlString, destFileName.FullName);
                    // File.WriteAllText(destFileName.FullName, bodyContent, Encoding.UTF8);
                    ReadXmlAndSaveData(documentKey,parentID, userId, clientId, destFileName.FullName, fileName, imageDirectoryName);
                }
            }
        }
        catch (Exception ex)
        {
            throw
        }
        return "";
    }

任何帮助都非常感谢。

0 个答案:

没有答案