.docx 파일을 읽고 첨부 파일이 아닌 전자 메일 본문으로 전자 메일에서 내용을 보내려고합니다.OpenXml Word 문서에서 헤더가있는 HTML로 변환
그래서 나는 docx 파일을 html로 변환하기 위해 openXML과 OpenXmlPowerTools를 사용합니다. 헤더 및 푸터 이미지가있는 문서를 얻을 때까지 이것은 거의 정상적으로 작동합니다.
다음은 위의 코드 HTML을using (WordprocessingDocument doc = WordprocessingDocument.Open(stream, true))
{
HtmlConverterSettings convSettings = new HtmlConverterSettings()
{
FabricateCssClasses = true,
CssClassPrefix = "cls-",
RestrictToSupportedLanguages = false,
RestrictToSupportedNumberingFormats = false,
ImageHandler = imageInfo =>
{
DirectoryInfo localDirInfo = new DirectoryInfo(imageDirectoryName);
if (!localDirInfo.Exists)
{
localDirInfo.Create();
}
++imageCounter;
string extension = imageInfo.ContentType.Split('/')[1].ToLower();
ImageFormat imageFormat = null;
if (extension == "png")
{
extension = "jpeg";
imageFormat = ImageFormat.Jpeg;
}
else if (extension == "bmp")
{
imageFormat = ImageFormat.Bmp;
}
else if (extension == "jpeg")
{
imageFormat = ImageFormat.Jpeg;
}
else if (extension == "tiff")
{
imageFormat = ImageFormat.Tiff;
}
// If the image format is not one that you expect, ignore it,
// and do not return markup for the link.
if (imageFormat == null)
{
return null;
}
string imageFileName = imageDirectoryName + "/image" + imageCounter.ToString() + "." + extension;
try
{
imageInfo.Bitmap.Save(imageFileName, imageFormat);
}
catch (System.Runtime.InteropServices.ExternalException)
{
return null;
}
XElement img = new XElement(Xhtml.img, new XAttribute(NoNamespace.src, imageFileName), imageInfo.ImgStyleAttribute, imageInfo.AltText != null ? new XAttribute(NoNamespace.alt, imageInfo.AltText) : null);
return img;
}
};
XElement html = OpenXmlPowerTools.HtmlConverter.ConvertToHtml(doc1, convSettings);
에 .DOCX 변환 내 코드는 잘 작동뿐만 아니라 이미지를 변환을하지만, 문서 헤더를 가지고 있으며, 바닥 글 경우 사람들은 변환되지 않습니다.
그래서 머리말과 꼬리말을 html 파일에 포함시키는 모든 해결책이 있습니다.
제발. 감사!
(이건 조금 부적절합니다.) MS Word Interop Assembly 대신 OpenXML SDK를 사용하는 특별한 이유가 있습니까? –
@AzazulHaq MS Word Interop Assembly에 MS Office가 필요하다고 생각합니다. 따라서이 문제를 피하십시오. –