-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathHtmlToDocxHelper.cs
38 lines (31 loc) · 1.13 KB
/
HtmlToDocxHelper.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace iDiTect.Converter.Demo
{
public static class HtmlToDocxHelper
{
public static void Convert()
{
HtmlToDocxConverter converter = new HtmlToDocxConverter();
string htmlContent = File.ReadAllText("sample.html");
converter.Load(htmlContent);
//Convert html to Word, and save it to local file
using (var stream = File.OpenWrite("convert.docx"))
{
converter.Save(stream);
}
}
public static void Convert2()
{
HtmlToDocxConverter converter = new HtmlToDocxConverter();
//Define the css for the html content
converter.DefaultStyleSheet = ".para{font-size: 24px; color: #FF0000;}";
string htmlContent = "<p class=\"para\">Content with special style.</p><p>Content without style</p>";
converter.Load(htmlContent);
File.WriteAllBytes("convert.docx", converter.SaveAsBytes());
}
}
}