C#使用Spire.Doc打印时候出现红字Evaluation Warning: The document was created with Spire.Doc for .NET.

1 篇文章 0 订阅

在这里插入图片描述
我们使用VS下面NuGet进行Spire.Doc安装,这个安装之后我们会出现水印,是因为我们这个没有付费导致的。
在这里插入图片描述
我们这里使用破解的Spire.Doc就能解决这个问题打印出来就没有这个问题了

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        List<string> printList = new List<string>();
        private void button1_Click(object sender, EventArgs e)
        {
            #region 创建待打印word
            //创建一个文档对象
            Document doc = new Document();
            //添加一个section
            Section section = doc.AddSection();

            //纸张横向
            Section sec = doc.Sections[0];
            sec.PageSetup.Orientation = PageOrientation.Landscape;

            //添加标题
            Paragraph inStoreTitle = section.AddParagraph();
            inStoreTitle.AppendText("入库单");
            //设置标题格式
            ParagraphStyle style1 = new ParagraphStyle(doc);
            style1.Name = "titleStyle";
            style1.CharacterFormat.Bold = true;
            style1.CharacterFormat.TextColor = Color.Black;
            style1.CharacterFormat.FontName = "方正小标宋简体";
            style1.CharacterFormat.FontSize = 24f;
            doc.Styles.Add(style1);
            inStoreTitle.ApplyStyle("titleStyle");
            //标题居中
            inStoreTitle.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
            //添加单号
            Paragraph pStrat = section.AddParagraph();
            pStrat.AppendText("单号:rkd" + DateTime.Now.ToString("yyyyMMddHHmmss"));
            //设置单号格式
            ParagraphStyle style12 = new ParagraphStyle(doc);
            style12.Name = "oddNumStyle";
            style12.CharacterFormat.Bold = false;
            style12.CharacterFormat.TextColor = Color.Black;
            style12.CharacterFormat.FontName = "宋体";
            style12.CharacterFormat.FontSize = 12f;
            doc.Styles.Add(style12);
            pStrat.ApplyStyle("oddNumStyle");

            //添加表格
            //Section section = doc.AddSection(); //添加section
            Table table = section.AddTable(true);
            //指定表格的行数和列数(11行,11列)
            table.ResetCells(11, 11);

            //标题行数组
            string[] tabTitle = { "入库编号", "货物编号", "货物名称", "仓库名称", "供货商", "规格", "计量单位", "单价", "入库数量", "入库总额", "经手人" };
            //添加表格标题行
            for (int i = 0; i < 1; i++)
            {
                for (int j = 0; j < 11; j++)
                {
                    TextRange range = table[i, j].AddParagraph().AppendText(tabTitle[j]);
                    range.CharacterFormat.FontName = "黑体";
                    range.CharacterFormat.FontSize = 12;
                    range.CharacterFormat.TextColor = Color.Black;
                    range.CharacterFormat.Bold = false;
                    table[i, j].Paragraphs[0].Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;  //水平居中
                    table[i, j].CellFormat.VerticalAlignment = VerticalAlignment.Middle;    //垂直居中
                }
            }
            printList.Add("rk201910222107#fxbl70001#华硕飞行堡垒7 i7 8G 256G#A仓库#联想专卖店#全新#台#6999#2#13998#小明");
            //遍历打印列表并插入表格数据
            for (int i = 0; i < printList.Count; i++)
            {
                string[] arr = printList[i].Split('#');
                for (int j = 0; j < 11; j++)
                {
                    TextRange range = table[i + 1, j].AddParagraph().AppendText(arr[j]);
                    range.CharacterFormat.FontName = "宋体";
                    range.CharacterFormat.FontSize = 10;
                    range.CharacterFormat.TextColor = Color.Black;
                    range.CharacterFormat.Bold = false;
                    table[i + 1, j].CellFormat.VerticalAlignment = VerticalAlignment.Middle;    //垂直居中
                }
            }
            //添加签字栏
            Paragraph pEnd = section.AddParagraph();
            pEnd.AppendText("制单人:              审核人:              日期:    年  月  日");
            //设置签字栏格式
            ParagraphStyle style13 = new ParagraphStyle(doc);
            style13.Name = "endLineStyle";
            style13.CharacterFormat.Bold = false;
            style13.CharacterFormat.TextColor = Color.Black;
            style13.CharacterFormat.FontName = "宋体";
            style13.CharacterFormat.FontSize = 12f;
            doc.Styles.Add(style13);
            pEnd.ApplyStyle("endLineStyle");

            //保存文档
            doc.SaveToFile("./inStoreDoc.docx", FileFormat.Docx2013);
            #endregion

            System.Threading.Thread.Sleep(1000);

            #region 开始打印
            //初始化PrintDialog实例
            PrintDialog dialog = new PrintDialog();

            //设置打印对话框属性
            dialog.AllowPrintToFile = true;
            dialog.AllowCurrentPage = true;
            dialog.AllowSomePages = true;

            //设置文档打印对话框
            doc.PrintDialog = dialog;

            //显示打印对话框并点击确定执行打印
            System.Drawing.Printing.PrintDocument printDoc = doc.PrintDocument;
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                printDoc.Print();
            }
            DeleDOC();
            #endregion
        }
        /// <summary>
        /// 删除insStoreDOC.docx文件
        /// </summary>
        public void DeleDOC()
        {
            if (System.IO.File.Exists("./inStoreDoc.docx"))
            {
                System.IO.File.Delete("./inStoreDoc.docx");
            }
        }
    }
}

下载资源Spire.Doc

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Free Spire.Doc 是一款免费的专门对 Word 文档进行操作的 .NET类库。适用于商业或个人用途。这款控件的主要功能在于帮助开发人员轻松快捷高效地创建、编辑、转换和打印 Microsoft Word 文档。作为一款独立的 Word .NET 控件,能执行多种 Microsoft Word 文档处理任务的 .NET API。支持 Word97-2003,Word2007,Word2010 以及 Word2013。能在 Word 97/2003/2007/2010/2013 和 XML、RTF、TXT、XPS、EPUB、EMF、HTML 等格式文件之间进行双向转换,还能将 Word 文件高质量地转换为 PDF 文件格式。 主要功能如下: 1. 高质量的文档转换。Free Spire.Doc for .NET 能帮助用户将 Word 文件保存在流中,也可以保存为 Web response,还支持将 Word 文件与 XML、RTF、EMF、 TXT、XPS、EPUB、HTML 等格式文件之间的双向转换。同时,它还支持将 Word 文件转换为 PDF 文件,HTML 文件转换为图像文件。 2. 多样化的 Word 文档功能。支持动态创建一个全新的 Word 文档,并支持几乎所有的 Word 文档元素,它们主要包括页面、节、页眉、页脚、脚注、尾注、段落、项目符号和编号、表格、 文本、域、超链接、书签、注释、图片、样式、背景设置、打印功能、文档设置和文档保护。同时,也支持形状、文本框、图片、OLE 对象和内容控件。 3. 对已有的 Word 文档进行操作处理。支持搜索和替换、设置对齐方式、分页、分节、填充域、文档合并、复制、打印以及邮件合并等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值