GoldPrinter(金质打印),这个打印的第三方插件很方便,可以直接利用excel模版套打,本人接触也不深,仅仅适合新手参考,本人也是在GoldPrinter提供的源代码参考后开发的。

具体顺序如下:

1、先画好excel表格模版

2、写代码给模版的单元格赋值

3、程序打印

好了,顺序基本就是这样了,做的是一个很简单的打印的例子,业务情况是这样的,一次性打印多个订单,一个订单对应多个商品,最后打印出三联单,打印如下图

好了,打印结果出来了,直接上代码。

 

private void button1_Click(object sender, EventArgs e)
        {
           //获取数据集合
            lt = getDelivery.GetDeliveryInfos(delivery_sn, order_sn, status);
            if (lt.Count < 1)
            {
                MessageBox.Show("当前条件没有数据", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else
            {
                for (int i = 0; i < lt.Count; i++)
                {
                    delivery dv = lt[i];
                    GoldPrinter.ExcelAccess excel = new GoldPrinter.ExcelAccess();
                    string strFileName = "送货单.xlt";            //模板文件名
                    string strExcelTemplateFile = System.AppDomain.CurrentDomain.BaseDirectory + "template//" + strFileName;
                    excel.Open(strExcelTemplateFile);                                //用模板文件
                    excel.IsVisibledExcel = true;
                    excel.SetCellText(3, "D", dv.customer_name);
                    excel.SetCellText(3, "H", dv.mobile);
                    excel.SetCellText(3, "K", dv.delivery_sn);
                    excel.SetCellText(4, "D", dv.address);
                    excel.SetCellText(4, "H", dv.order_sn);
                    excel.SetCellText(4, "K", dv.delivery_date);
                    List<good> lt_good = dv.goodList;
                    for (int j = 0; j < (lt_good.Count > 10 ? 10 : lt_good.Count); j++)
                    {
                        excel.SetCellText(6 + j, "B", (1 + j).ToString());
                        excel.SetCellText(6 + j, "C", lt_good[j].name);
                        excel.SetCellText(6 + j, "F", "");//规格
                        excel.SetCellText(6 + j, "G", "");//单位
                        excel.SetCellText(6 + j, "H", lt_good[j].number.ToString());
                        excel.SetCellText(6 + j, "I", lt_good[j].price.ToString("0.00"));
                        excel.SetCellText(6 + j, "J", lt_good[j].totalmoney.ToString("0.00"));
                        excel.SetCellText(6 + j, "K", "");//备注
                    }
                    string upperMoney = GoldPrinter.ChineseNum.GetUpperMoney(Double.Parse(excel.GetCellText(16, "J")));
                    excel.SetCellText(16, "E", upperMoney);
                    excel.PrintPreview();
                    excel.Close();                    //关闭并释放
                    Thread.Sleep(500);
                }
            }
        }    
View Code

以上是预览打印,如果需要直接打印只需把excel.PrintPreview()直接改成excel.Print()即可。其中涉及到两个DLL,具体看附件

 DLL包

GoldPrinter源代码

posted on 2015-10-19 11:10  Jeton  阅读(1932)  评论(1编辑  收藏  举报