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中的图片大 ...
随机推荐
- SqlServer2008基础知识:安全与权限
分享自 儒雅的男人blog http://www.cnblogs.com/yushaoye201314/archive/2013/04/19/3031203.html 好文,转载收藏 这两天在调用Mi ...
- ASP.NET获取文件名,后缀名
using System.IO; //引入命名空间 string path = "text.aspx"; string pathName = Path.GetFileName(pa ...
- mysql 找不到或无法加载已注册的 .Net Framework Data Provider和Unable to find the requested .Net Framework Data Provider. It may not be installed解决
需要安装 mysql-connector-net-6.7.4.msi 在C盘安装mysql的位置找到三个DLL,复制到Bin文件夹下 在Web.config文件中添加对应配置: <system. ...
- 在 ubuntu 【6.06、6.10】 上安装 oracle 10.2.0.1,并打补丁 10.2.0.5
特点: ubuntu 6.06.6.10 算是很古老的ubuntu了,其应该是基于 debian 4 的 tesing/unstable 分支.所以,毛病较多. 如何安装oracle10g? 几个技术 ...
- proto序列化
proto序列化和反序列化类 序列化是将我们的Protobuf类对象转换成字节数组的方法,网络底层我们从服务器获取到的是字节数组,反序列化是将字节转成proto类对象的方法 public class ...
- 详解ABBYY FineReader 12扫描亮度设置
很多刚接触ABBYY FineReader 12的小伙伴可能出现过这样一个问题:在扫描过程中会显示一条消息以提示更改亮度设置.这是因为你 FineReader扫描设置中亮度未正确设置.下面小编就给小伙 ...
- TV和BTV(全变分和双边全变分)
TV:Total Variation BTV:Bilateral Total Variation Osher等在1992 年提出了总变分(TV)超分辨率重建方法,该方法能够有效地去除噪声和消除模糊,但 ...
- PHP框架 Yii framework 用yiic命令时提示“php.exe”不是内部或外部命令
解决方案 yii/framework/yiic.bat,修改 if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exei ...
- SpringBoot自动配置xxxAutoConfiguration 的使用
https://sdqali.in/blog/2016/07/16/controlling-redis-auto-configuration-for-spring-boot-session/ 常用的类 ...
- SpringMVC由浅入深day02_10拦截器
10 拦截器 Spring Web MVC 的处理器拦截器类似于Servlet 开发中的过滤器Filter,用于对处理器进行预处理和后处理. 10.1 拦截定义 定义拦截器,实现HandlerInte ...