DocX Xceed.Words.NET操作Word,插入特殊符号
x
传送门,我们走...
开始...
自己做一个工具,要导出Word的,当时刚开始想使用Xceed.Words.NET.dll第三方插件进行开发。
但是网络上真的找不到太多相关资料来进行参考的好不好(不知道当初为毛要选择这个,听说很强大?)
然后搜到了中文资料比较多的一个第三方的插件:DocX.dll,听说也挺好用的。好吧就用它了,
并且找到了Github地址(本文中第一个门),下载一个Demo下来(感觉根据Demo调试生成下,一般操作完全Ok了),
生成Word,修改一下,感觉还不错。接着问题来了...Word中要插入特殊符号,
生成Word + 特殊符号...
/// <summary>
/// 生成Word
/// </summary>
public byte[] GetWordByte()
{
byte[] bytes = null;
try
{
List<string> list = new List<string>()
{
"我想要","生成","的数据。"
};
if (list.Count > )
{
string rootFolderPath = System.Configuration.ConfigurationManager.AppSettings["UploadFileAddress"]; ;//跟文件夹路径
int intUserID = XY.Global.XYRequestCache.RequestState.UserID;
string folderPath = "C:\\TestPath\\Word\\";
string fileName = "\\" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + "测试.docx";
string filePath = folderPath + fileName;
XYFileSystem FileSystem = new XYFileSystem();
if (File.Exists(folderPath))
{
System.IO.Directory.CreateDirectory(folderPath);
}
// Create a new document.
using (DocX document = DocX.Create(filePath))
{
// Add a title
//document.InsertParagraph("Adding Custom Properties to a document").FontSize(15d).SpacingAfter(50d).Alignment = Alignment.center;
foreach (var item in list)
{
double fontSize = 14d;
Paragraph retPar = document.InsertParagraph().Font("宋体").FontSize(fontSize);
retPar.Append(item).Font("宋体").FontSize(fontSize).AppendLine();
//特殊符号 //空心圆形
retPar.Append(string.Concat("\u25CB", "空心圆形A")).Font("宋体").FontSize(fontSize);
retPar.Append(string.Concat("\u25CB", "空心圆形B")).Font("宋体").FontSize(fontSize); //空心方形
retPar.Append(string.Concat("\u25A1", "空心方形A")).Font("宋体").FontSize(fontSize);
//下面示例中的特殊符号
if ("男" == "男")//纯属YuLe...
{
retPar.Append("\u0052男\u00A3女").Font("Wingdings 2").FontSize(fontSize);//这里设置字体类型
}
else
{
retPar.Append("\u0052女\u00A3男").Font("Wingdings 2").FontSize(fontSize);//这里设置字体类型
} } document.AddFooters(); //要添加的页脚,标识页数
//偶数[2,4,6,8...]页脚的样式...
// Add the page number in the even Footers.
//document.Footers.Even.InsertParagraph("").Font("Times New Roman").FontSize(9).AppendPageNumber(PageNumberFormat.normal);
var evenFooter = document.Footers.Even.InsertParagraph();
evenFooter.Font("Times New Roman").FontSize();
evenFooter.Alignment = Alignment.center;
document.Footers.Even.InsertParagraph(evenFooter).AppendPageNumber(PageNumberFormat.normal); //奇数[1,3,5,7...]页脚的样式...
// Add the page number in the odd Footers.
//document.Footers.Odd.InsertParagraph("").Font("Times New Roman").FontSize(9).AppendPageNumber(PageNumberFormat.normal);
var oddFooter = document.Footers.Even.InsertParagraph();
oddFooter.Font("Times New Roman").FontSize();
oddFooter.Alignment = Alignment.center;
document.Footers.Odd.InsertParagraph(oddFooter).AppendPageNumber(PageNumberFormat.normal); // Save this document to disk.
document.Save();
} #region 将文件转换为byte[]
//if (!File.Exists(filePath)) return null;
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
try
{
byte[] buffur = new byte[fs.Length];
fs.Read(buffur, , (int)fs.Length); bytes = buffur;
}
catch (Exception)
{
return null;
}
finally
{
if (fs != null)
{
fs.Close();
}
}
}
#endregion //清理痕迹,打扫磁盘战场...
File.Delete(filePath);
} return bytes;
}
catch (Exception)
{
//DO sth ...
}
return bytes;
}
特殊符号
这个绝对是,找了好长时间才找到!!!
直接复制原文了...
当我们要在word中输入选择框和打钩的选择框,我们可以这样:插入->符号->字体选择“Wingdings 2”。里面就有我们需要的选择框。

这里我们看到我们需要的打钩选择框的,字体是Wingdings 2,然后16进制的字符代码是0052,这样我们就可以利用这个来实现我们需要的字符
用之前同样的模板但是我们希望在性别这一栏采用选中框的方式展现效果,类似这样的//请看上面的代码...

写在最后...
一切都搞完了,回头看了下DocX的GitHub主页...
发现原来是一回事,但是免费的中文资料就还行,付费的真的不太好找...
"
DocX is the free, open source version of Xceed Words for .NET. Originally written by Cathal Coffey, and maintained by Przemyslaw Klys, it is now maintained by Xceed.
Currently, the only difference between DocX and Xceed Words for .NET, is that Xceed Words for .NET can convert a Word document to PDF, and has professional technical support included in the subscription.
"
| Edition | DocX | Xceed Words for .NET |
| Price | Free | $499.95 |
| License | Ms-PL | Proprietary |
| 我只是 | 添加错了我... |
| 并且不 | 知道怎么删这个表格.. |
x
DocX Xceed.Words.NET操作Word,插入特殊符号的更多相关文章
- c#调用Aspose.Word组件操作word 插入文字/图片/表格 书签替换套打
由于NPOI暂时没找到书签内容替换功能,所以换用Apose.Word组件. using System; using System.Collections.Generic; using System.C ...
- C# 操作Word文本框——插入表格/读取表格/删除表格
在文本框中,我们可以操作很多元素,如文本.图片.表格等,在本篇文章中将着重介绍如何插入表格到文本框,插入的表格我们可以对表格进行格式化操作来丰富表格内容.此外,对于文本框中的表格内容,我们也可以根据需 ...
- C# 操作Word 中的OLE——插入、编辑、读取 OLE
概述 OLE,Object Linking and Embedding,即对象连接与嵌入.我们在设计程序时,OLE可以用来创建复合文档,把文字.声音.图像.表格.应用程序等类型的信息组合在一起,在Wo ...
- C# 操作Word书签(二)——插入图片、表格到书签;读取、替换书签
概要 书签的设置可以帮助我们快速的定位某段文字,使用起来很方便,也很节省时间.在前一篇文章“C# 如何添加/删除Word书签”中介绍了插入.删除书签的方法,本篇文章将对C# 操作Word书签的功能做进 ...
- C#/VB.NET 操作Word批注(二)——如何插入图片、读取、回复Word批注内容
序 在前面的文章C# 如何插入.修改.删除Word批注一文中介绍了如何操作Word批注的一些方法,在本篇文章中继续介绍操作Word批注的方法.分以下三种情况来介绍: 1. 插入图片到Word批注 2. ...
- C# /VB.NET操作Word批注(一)—— 插入、修改、删除Word批注
批注内容可以是对某段文字或内容的注释,也可以是对文段中心思想的概括提要,或者是对文章内容的评判.疑问,以及在阅读时给自己或他人起到提示作用.本篇文章中将介绍如何在C#中操作Word批注,主要包含以下要 ...
- DocX操作word生成报表
1.DocX简介 1.1 简介 DocX是一个在不需要安装word的情况下对word进行操作的开源轻量级.net组件,是由爱尔兰的一个叫Cathal Coffey的博士生开发出来的.DocX使得操作w ...
- C#操作word模板插入文字、图片及表格详细步骤
c#操作word模板插入文字.图片及表格 1.建立word模板文件 person.dot用书签 标示相关字段的填充位置 2.建立web应用程序 加入Microsoft.Office.Interop.W ...
- C#操作Word文档(加密、解密、对应书签插入分页符)
原文:C#操作Word文档(加密.解密.对应书签插入分页符) 最近做一个项目,客户要求对已经生成好的RTF文件中的内容进行分页显示,由于之前对这方面没有什么了解,后来在网上也找了相关的资料,并结合自己 ...
随机推荐
- 深入浅出UE4网络
UE4中的官方文档结构比较混乱,且有部分错误,不方便学习.笔者试图通过本文,整理出一篇关于UE4网络的文章,方便朋友们对UE4中的网络同步部分的认识,并有进一步理解.如有讲得不清楚明白的地方,还望批评 ...
- django上下文处理器的基本使用
1.定义一个方法 2.在django里面的settings.py里面修改配置文件 3.最后在模板里面调用 操做步骤如下: 这是在settings.py里面配置的文件 在模板里面调用上下文处理器
- 转:spring boot log4j2配置(使用log4j2.yml文件)---YAML 语言教程
转:spring boot log4j2配置(使用log4j2.yml文件) - CSDN博客http://blog.csdn.net/ClementAD/article/details/514988 ...
- for 循环 与forEach 里面return 的区别
for 循环里面 return 可以直接终止 跳出 循环 forEach 是中断本次循环 直接 下一个循环 forEach想要取到值之后 直接跳出循环 可以用 try catch let arr = ...
- python中的赋值操作
参考:https://www.cnblogs.com/andywenzhi/p/7453374.html?tdsourcetag=s_pcqq_aiomsg(写的蛮好) python中的赋值操作“=” ...
- 【easy】112.path sum 113.-----------------
求是否有从根到叶的路径,节点和等于某个值. /** * Definition for a binary tree node. * struct TreeNode { * int val; * Tree ...
- 【easy】power of 2,3,4
============================== 2的幂次 ================================ 最佳解法 如果一个数是2的次方数的话,根据上面分析,那么 ...
- 【原创】大叔经验分享(26)hive通过外部表读写elasticsearch数据
hive通过外部表读写elasticsearch数据,和读写hbase数据差不多,差别是需要下载elasticsearch-hadoop-hive-6.6.2.jar,然后使用其中的EsStorage ...
- java----SAX解析XML
XML: 可扩展标记语言 1.充当显示数据 2.储存数据 3.传输数据 SAX: 水电费 基于事假驱动,顺序读写,速度快 不能任意读取节点,灵活性差 解析时,占用内存小 import org.xml. ...
- jquery 第三章
1.回顾$(document).ready(function(){ })$(function(){ }) ID选择器.类选择器.元素选择器层次选择器:空格(上文下:tr td{})属性过滤 ...