[C#] 纯文本查看 复制代码 private void GetImagesFromWord(string strFileName)
{
using (RichEditDocumentServer srv = new RichEditDocumentServer())
{
srv.LoadDocument(strFileName);
DevExpress.XtraRichEdit.API.Native.Document doc = srv.Document;
DevExpress.XtraRichEdit.API.Native.ParagraphCollection parCol = doc.Paragraphs;
DocumentImageCollection dic = doc.GetImages(doc.Range);
if (dic.Count == 0)
return;
//创建文件夹
int index = strFileName.LastIndexOf('.');
if (index == -1)
return;
string strDir = strFileName.Substring(0, index);
if(!Directory.Exists(strDir))
Directory.CreateDirectory(strDir);
int i = 0;
foreach (DocumentImage di in dic)
{
i++;
string strNewFileName = strDir + "\\";
DevExpress.Office.Utils.OfficeImage officeImage = di.Image;
string strSuffix = i.ToString()+".";
switch (officeImage.RawFormat) {
case DevExpress.Office.Utils.OfficeImageFormat.Bmp:
strSuffix += "bmp";
break;
case DevExpress.Office.Utils.OfficeImageFormat.Gif:
strSuffix += "gif";
break;
case DevExpress.Office.Utils.OfficeImageFormat.Jpeg:
strSuffix += "jpg";
break;
case DevExpress.Office.Utils.OfficeImageFormat.Png:
strSuffix += "png";
break;
case DevExpress.Office.Utils.OfficeImageFormat.Icon:
strSuffix += "ico";
break;
case DevExpress.Office.Utils.OfficeImageFormat.Emf:
strSuffix += "emf";
break;
case DevExpress.Office.Utils.OfficeImageFormat.Wmf:
strSuffix += "wmf";
break;
default:
strSuffix += "bmp";
break;
}
strNewFileName += strSuffix;
File.WriteAllBytes(strNewFileName, officeImage.GetImageBytes(officeImage.RawFormat));
}
}
}
|