DocX Xceed.Words.NET操作Word,插入特殊符號


x

傳送門,我們走...

DocX的Github傳送門

介紹一

介紹二

寫入特殊符號

開始...

自己做一個工具,要導出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 > 0)
        {
            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(9); 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(9); 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, 0, (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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM