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的更多相关文章
- Openxml 笔记
用openxml 生成Excel: private void GenerateExcelUsingOpenxml(DataTable dataTable, string GeneratePath) ...
- 【整理】Word OpenXML常用标签
一.背景 最近在做关于Word内容自动标引,需要了解Word的底层结构,顺便梳理一下OpenXML的标签含义,方便后续开发,提高对OpenXML标签的查找效率,也是一个熟悉的过程. 二.内容 < ...
- OpenXml Sdk 根据Word模板导出到word
一:OpenXml Sdk 简介 Open XML标准的简单介绍:Ecma Office Open XML(“Open XML”)是针对字处理文档.演示文稿和电子表格的国际化开放标准,可免费供多个应用 ...
- openxml(二) 添加页眉,页脚
openxml 中 word 文档的结构是如下图: 其中,页眉是 header,属于headerpart 部件,页脚是footer,属于footerpart 部件,图上还有其他的东西,之后会一一介绍. ...
- SQL中的OpenXML使用
DECLARE @idoc int ) SET @doc =' <ROOT> <Customer CustomerID="VINET" ContactName=& ...
- 一个用微软官方的OpenXml读写Excel 目前网上不太普及的方法。
新版本的xlsx是使用新的存储格式,貌似是处理过的XML. 传统的excel处理方法,我真的感觉像屎.用Oldeb不方便,用com组件要实际调用excel打开关闭,很容易出现死. 对于OpenXML我 ...
- csharp:using OpenXml SDK 2.0 and ClosedXML read excel file
https://openxmlexporttoexcel.codeplex.com/ http://referencesource.microsoft.com/ 引用: using System; u ...
- 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 ...
- Openxml入门---Openxm读取Excel数据
Openxml读取Excel数据: 有些问题,如果当Cell 里面是 日期和浮点型的话,对应的Cell.DataType==Null,对应的时间会转换为一个浮点型,对于这块可以通过DateTime.F ...
- OpenXml入门---word里面插入图片
下面介绍如何在word里面插入图片,顺便小弟发现MSDN官网有完整的OpenXML教程,虽然是全英文的不过还是很有帮助的. Tips,原来摘抄代码里面没有模板,在copy过来发现插入word中的图片大 ...
随机推荐
- qq划屏幕红包程序
qq划屏幕红包程序
- greenplum日常维护手册
1. 数据库启动:gpstart 常用可选参数: -a : 直接启动,不提示终端用户输入确认 -m:只启动master 实例,主要在故障处理时使用 2. 数据库停止:gpsto ...
- Java实习生面试题整理
一.数据类型 包装类型 八个基本类型: boolean/1 byte/8 char/16 short/16 int/32 float/32 long/64 double/64 基本类型都有对应的包装类 ...
- nodejs包管理工具npm
用Node.js安装模块 在某个项目中单独安装的时候,npm会下载所有的文件到你项目中的一个叫做node_modules的文件夹内 全局模块会被安装到{prefix}/lib/node_modules ...
- PDCA 价值所在
企业IT服务管理实施 不提倡一步到位 对企业IT部门来说,实施ITIL Service Support(服务支持)的意义在于清晰梳理日常IT运维管理过程中遇到的各种各样的事,使IT运维过程变得有序连贯 ...
- anaconda-ks.cfg详解
https://blog.csdn.net/whyhonest/article/details/7555229
- feign的callback设定后,项目启动错误
错误如下: Error starting ApplicationContext. To display the auto-configuration report re-run your applic ...
- swagger的说明、配置及使用
一.What is swagger? 官方介绍:Swagger是一个规范且完整的框架,提供描述.生产.消费和可视化RESTful Web Service.专业角度:Swagger是由庞大工具集合支撑的 ...
- python 字符串格式化,使用f前缀
格式化一般用%,但后来推荐用format format有进步,可以用索引或者名字,但仍然没有很方便和快捷 # logger.debug('{} {} {} {} {} {}'.format(metho ...
- 《倾国倾城》全套源代码:client+服务端+资源,歧视复制帖子
郝萌主倾心贡献,尊重作者的劳动成果,请勿转载. 假设文章对您有所帮助,欢迎给作者捐赠,支持郝萌主,捐赠数额任意.重在心意^_^ 我要捐赠: 点击捐赠 Cocos2d-X源代码下载:点我传送 游戏官方下 ...