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. linux command not found错误提示

    错误提示:screen: command not found, 如果提示screen: command not found 命令不存在可以执行:yum install screen 或 apt-get ...

  2. SharePoint 2013 处理Promoted Links类型的List下的Tiles View的默认Webpart展示方式

    问题: 为了去掉Photo Gallery的水平滚动效果,更改为根据内容进行自适应宽度多行显示效果 Promoter link --> photo gallery Not horizontal ...

  3. VMware Workstation “The Msi Failed”解决方法

    今天准备装虚拟机时,遇到一个问题一直没办法解决.折腾了一下午,总算解决了.在这里记录以下,以便大家遇到相同的问题时,能尽快解决. 由于以前安装过WMware Workstation,然后又卸载了.今天 ...

  4. Servlet3简介

    servlet基础知识:http://blog.csdn.net/chjttony/article/details/6086292 ServletContext相关知识:http://blog.csd ...

  5. Tensorflow同时加载使用多个模型

    在Tensorflow中,所有操作对象都包装到相应的Session中的,所以想要使用不同的模型就需要将这些模型加载到不同的Session中并在使用的时候申明是哪个Session,从而避免由于Sessi ...

  6. vuejs监听苹果iphone手机键盘事件

    在iphone手机中,vue提供的keyup事件是不能监听iphone键盘的,但是h5提供的input事件可以做到. 只需要向下面这样处理,就可以解决iphone不响应键盘事件的bug <tem ...

  7. linux 信息收集脚本。转自insight-labs

    找出所有.sh .pl .py .conf .cnf .ini .*history .*pass* (/usr/share目录里面的除外) 并且在当前目录zip打包.有些时候很多配置文件的权限配置不严 ...

  8. requests 安装

    requests 是用来发送 HTTP 请求的一个库,requests 是对 urllib 和 urllib2 进行封装的一个模块,用来取代 urllib 和 urllib2,可以使用以下两种方法安装 ...

  9. CentOS7--TigerVNC

    --安装服务yum install tigervnc-server -y --配置文件,多个用户就拷贝多个cp /lib/systemd/system/vncserver@.service /etc/ ...

  10. zabbix的启动和关闭脚本

    1. zabbix客户端的系统服务脚本 1.1 拷贝启动脚本 zabbix的源码提供了系统服务脚本,在/usr/local/src/zabbix-3.2.6/misc/init.d目录下,我的系统是C ...