Html to OpenXml

How to start ?

Create a new console application. Add a reference to DocumentFormat.OpenXml.dll (shipped with the OpenXml SDK 2.0).
Add an html file and fill it with:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
Looks how cool is <font size="x-large"><b>Open Xml</b></font>.
Now with <font color="red"><u>HtmlToOpenXml</u></font>, it nevers been so easy to convert html.
<p>
If you like it, add me a rating on <a href="http://notesforhtml2openxml.codeplex.com">codeplex</a>
</p>
<hr>
</body>
</html>

Add a Resources.resx component and add your html file inside it.

In Program.cs, add these lines of code:

using System.IO;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using NotesFor.HtmlToOpenXml;
... static void Main(string[] args)
{
const string filename = "test.docx";
string html = Properties.Resources.DemoHtml; if (File.Exists(filename)) File.Delete(filename); using (MemoryStream generatedDocument = new MemoryStream())
{
using (WordprocessingDocument package = WordprocessingDocument.Create(generatedDocument, WordprocessingDocumentType.Document))
{
MainDocumentPart mainPart = package.MainDocumentPart;
if (mainPart == null)
{
mainPart = package.AddMainDocumentPart();
new Document(new Body()).Save(mainPart);
} HtmlConverter converter = new HtmlConverter(mainPart);
Body body = mainPart.Document.Body; var paragraphs = converter.Parse(html);
for (int i = 0; i < paragraphs.Count; i++)
{
body.Append(paragraphs[i]);
} mainPart.Document.Save();
} File.WriteAllBytes(filename, generatedDocument.ToArray());
} System.Diagnostics.Process.Start(filename);
}

html to openxml的更多相关文章

  1. Openxml 笔记

    用openxml 生成Excel: private void GenerateExcelUsingOpenxml(DataTable dataTable, string GeneratePath)   ...

  2. 【整理】Word OpenXML常用标签

    一.背景 最近在做关于Word内容自动标引,需要了解Word的底层结构,顺便梳理一下OpenXML的标签含义,方便后续开发,提高对OpenXML标签的查找效率,也是一个熟悉的过程. 二.内容 < ...

  3. OpenXml Sdk 根据Word模板导出到word

    一:OpenXml Sdk 简介 Open XML标准的简单介绍:Ecma Office Open XML(“Open XML”)是针对字处理文档.演示文稿和电子表格的国际化开放标准,可免费供多个应用 ...

  4. openxml(二) 添加页眉,页脚

    openxml 中 word 文档的结构是如下图: 其中,页眉是 header,属于headerpart 部件,页脚是footer,属于footerpart 部件,图上还有其他的东西,之后会一一介绍. ...

  5. SQL中的OpenXML使用

    DECLARE @idoc int ) SET @doc =' <ROOT> <Customer CustomerID="VINET" ContactName=& ...

  6. 一个用微软官方的OpenXml读写Excel 目前网上不太普及的方法。

    新版本的xlsx是使用新的存储格式,貌似是处理过的XML. 传统的excel处理方法,我真的感觉像屎.用Oldeb不方便,用com组件要实际调用excel打开关闭,很容易出现死. 对于OpenXML我 ...

  7. csharp:using OpenXml SDK 2.0 and ClosedXML read excel file

    https://openxmlexporttoexcel.codeplex.com/ http://referencesource.microsoft.com/ 引用: using System; u ...

  8. csharp: Export DataTable to Excel using OpenXml 2.5 in asp.net

    //https://www.microsoft.com/en-us/download/details.aspx?id=5124 Open XML SDK 2.0 for Microsoft Offic ...

  9. Openxml入门---Openxm读取Excel数据

    Openxml读取Excel数据: 有些问题,如果当Cell 里面是 日期和浮点型的话,对应的Cell.DataType==Null,对应的时间会转换为一个浮点型,对于这块可以通过DateTime.F ...

  10. OpenXml入门---word里面插入图片

    下面介绍如何在word里面插入图片,顺便小弟发现MSDN官网有完整的OpenXML教程,虽然是全英文的不过还是很有帮助的. Tips,原来摘抄代码里面没有模板,在copy过来发现插入word中的图片大 ...

随机推荐

  1. JS检查当图片不存在时显示默认图片和键盘大小写键状态

    当图片不存在时显示默认图片 <script type="text/javascript"> var imgs = document.images; for(var i ...

  2. 【Ubuntu】全局代理

    配置代理,Ubuntu下是修改/etc/environment,在后面加入: http_proxy="http://****.com:8080/" https_proxy=&quo ...

  3. JIRA 初体验

    JIRA 使用神奇的JQL查询数据,很nice啊 ! 官网API:   https://docs.atlassian.com/jira/REST/latest/#d2e2344 测试一下search: ...

  4. QT基础:QT 定时器学习

    定时器在编程中经常要用到,有必要学习一下,记记笔记! Qt中定时器的使用有两种方法,一种是使用QObject类提供的定时器,还有一种就是使用QTimer类. 1.QObject中的定时器的使用,需要用 ...

  5. VMware12多台虚拟机上网设置

    1.根据镜像安装好linux系统, 2.  把网络适配器移除后,重新添加试试 3. 当按照上述配置后还是无法上网,把VMnet0 桥接模式的自动 ,这里重新点击下自动设置(其实没有做到自动配置) 4. ...

  6. go interface介绍

    http://legendtkl.com/2017/06/12/understanding-golang-interface/      深入理解 Go Interface http://legend ...

  7. go语言之PLAN9汇编

    http://blog.studygolang.com/2013/05/asm_and_plan9_asm/ https://lrita.github.io/2017/12/12/golang-asm ...

  8. 怎样把网站升级到http/2

    https://juejin.im/post/59c63adf6fb9a00a4c271484

  9. JointJS绘制流程图

    摘要: JointJS是一个javascript图表库.你可以使用它制作静态或者动态的图表.关系表.流程图. 效果图:

  10. nginx配置设置,使部分页面访问跳转到404页面

    location ~* /(ask|hospital|wenda|regsearch|user|doctor) { return ; } error_page /.html;