日期:2014-05-17  浏览次数:21037 次

C#如何编写POS机打印小票功能
我最近要用C#编写POS机打印小票功能,可是不知道该如何写,还有就是小票打印完之后是POS机的自动裁纸,还是我的C#程序里自己编写裁纸功能啊。。。。困惑啊,没有思路...能给个实例嘛。

------解决方案--------------------
你先创建一个EXCEL表格,设置好打印区域还有打印机打印的纸张大小。定义了打印纸张后打印,他就会自动停在你打印的位置...建好模板后,在C#中引用EXCEL就像这样
C# code
Microsoft.Office.Interop.Excel.Application excel = null;
            Microsoft.Office.Interop.Excel.Workbook xBook = null;
            Microsoft.Office.Interop.Excel._Worksheet wks = null;
            string dataFilePath = System.Environment.CurrentDirectory + @"\Model.xls";
            try
            {
                excel = new Microsoft.Office.Interop.Excel.Application();
                excel.Visible = false;
                excel.DisplayAlerts = false;
                //excel.ActivePrinter = "Citizen CLP-521Z";
                xBook = excel.Application.Workbooks._Open(dataFilePath, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing);

                if (xBook == null)
                {
                    xBook = excel.Application.Workbooks.Add(true);
                }

                wks = (Microsoft.Office.Interop.Excel._Worksheet)xBook.ActiveSheet; //取得当前worksheet 
                wks.Cells[2, 2] = "'" + sScheduleDate;//.Remove(10);
                wks.Cells[3, 2] = "'" + sPatientID;
                wks.Cells[4, 2] = "'" + sName;
                wks.Cells[5, 2] = "'" + sSex;
                wks.Cells[5, 4] = "'" + nAge;
                wks.Cells[6, 2] = "'" + sCheckType;
                object omo = new object();
                //打印预览
                //wks.PrintPreview(omo);
                //不预览打印
                wks.PrintOut(1, 1, 1, false, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
                //wks.PrintOut(omo, omo, omo, omo, omo, omo, omo, omo);
                //xBook.Saved = true;
                xBook.Save();
                excel.Application.Workbooks.Close();
                excel.Application.Quit();
                excel.Quit();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);

------解决方案--------------------
http://apps.hi.baidu.com/share/detail/31171999


http://gbigone.blog.163.com/blog/static/350015292009101831349542/