-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExportActions.cs
53 lines (49 loc) · 2.28 KB
/
ExportActions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using DevExpress.XtraRichEdit.API.Native;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DXRichEditControlAPISample.CodeExamples
{
class ExportActions
{
static void SaveImageFromRange(Document document)
{
#region #SaveImageFromRange
document.LoadDocument("Documents//Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
DocumentRange docRange = document.Paragraphs[2].Range;
ReadOnlyDocumentImageCollection docImageColl = document.Images.Get(docRange);
if (docImageColl.Count > 0)
{
DevExpress.Office.Utils.OfficeImage myImage = docImageColl[0].Image;
System.Drawing.Image image = myImage.NativeImage;
string imageName = String.Format("Image_at_pos_{0}.png", docRange.Start.ToInt());
image.Save(imageName);
System.Diagnostics.Process.Start("explorer.exe", "/select," + imageName);
}
#endregion #SaveImageFromRange
}
static void ExportRangeToHtml(Document document)
{
#region #ExportRangeToHtml
document.LoadDocument("Documents//Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
// Get the range for three paragraphs.
DocumentRange r = document.CreateRange(document.Paragraphs[0].Range.Start, document.Paragraphs[0].Range.Length + document.Paragraphs[1].Range.Length + document.Paragraphs[2].Range.Length);
// Export to HTML.
string htmlText = document.GetHtmlText(r, null);
System.IO.File.WriteAllText("test.html", htmlText);
// Show the result in a browser window.
System.Diagnostics.Process.Start("test.html");
#endregion #ExportRangeToHtml
}
static void ExportRangeToPlainText(Document document)
{
#region #ExportRangeToPlainText
document.LoadDocument("Documents//Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
string plainText = document.GetText(document.Paragraphs[2].Range);
System.Windows.Forms.MessageBox.Show(plainText);
#endregion #ExportRangeToPlainText
}
}
}