-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathDocxToTxtHelper.cs
69 lines (56 loc) · 2.07 KB
/
DocxToTxtHelper.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
namespace iDiTect.Converter.Demo
{
public static class DocxToTxtHelper
{
public static void Convert()
{
DocxToTxtConverter converter = new DocxToTxtConverter();
//Load Word document from stream
using (Stream stream = File.OpenRead("sample.docx"))
{
converter.Load(stream);
}
//Convert Word to txt, and save it to hard disk
File.WriteAllText("convert.txt", converter.SaveAsString());
}
public static void Replace()
{
DocxToTxtConverter document = new DocxToTxtConverter();
//Load Word document from stream
using (Stream stream = File.OpenRead("sample.docx"))
{
document.Load(stream);
}
//Indicates whether the casing should be matched
document.MatchCase = true;
//Indicates whether only whole words should be matched
document.MatchWholeWord = true;
//Replace target text in whole document
document.ReplaceText("old text", "new text");
using (Stream stream = File.OpenWrite("ReplaceText.docx"))
{
document.SaveAfterReplace(stream);
}
}
public static void Highlight()
{
DocxToTxtConverter document = new DocxToTxtConverter();
document.Load(File.ReadAllBytes("sample.docx"));
//Indicates whether the casing should be matched
document.MatchCase = true;
//Indicates whether only whole words should be matched
document.MatchWholeWord = true;
//Define highlight color
document.HighlightColor = Color.Yellow;
//Highlight target text in whole document
document.HighlightText("select text");
File.WriteAllBytes("HighlightText.docx", document.SaveAfterReplace());
}
}
}