調用codeSoft的模板,實現批量連續打印。ui
Code:this
製做標籤1.lab.spa
添加兩個變量var0,var1。code
using LabelManager2; string strFile = System.Windows.Forms.Application.StartupPath.ToString() + "\\1.lab"; lbl = new LabelManager2.ApplicationClass(); lbl.Documents.Open(strFile, false);//調用設好的lbl標籤 doc = lbl.ActiveDocument; //得到全部打印機名稱 Strings vars = lbl.PrinterSystem().Printers(enumKindOfPrinters.lppxAllPrinters); //得到須要的打印機名稱 打印機固定可直接給名稱值 // string printName = vars.Item(2); PrintDocument prtdoc = new PrintDocument(); string strDefaultPrinter = prtdoc.PrinterSettings.PrinterName;//獲取默認的打印機名 for (int j = 0; j < vars.Count; j++) { string[] arryString = vars.Item(j).Split(','); if (arryString[0] == strDefaultPrinter) { doc.Printer.SwitchTo(strDefaultPrinter, arryString[1], true); break; } } DataTable dt = codeInfo_DAL.GetData(this.cbb.SelectedValue.ToString()); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { //codesoft模板中標籤變量 doc.Variables.FormVariables.Item("var0").Value = dr["CodeID"].ToString(); doc.Variables.FormVariables.Item("var1").Value =dr["Name"].ToString(); // doc.PrintDocument(3); doc.PrintLabel(1, 1, 1, 1, 1, ""); } //標籤批量連續打印。FormFeed()必須等參數變量輸出後才執行,輸出給打印機。 doc.FormFeed(); lbl.Quit(); }
codesoft模板,128碼下方文字間距設置。orm