1. Add Reference... Interop.LabelManager2.dll, dll與.exe相同目錄
2. Lppx2.tlb與.exe相同目錄
3..NET Framework 3.5
LabelManager2.ApplicationClass lbl = null;
LabelManager2.Document doc = null;
if (strLabelExtension.IndexOf("LAB", StringComparison.OrdinalIgnoreCase) >= 0)
{
lbl = new LabelManager2.ApplicationClass();
lbl.Documents.Open(strLabelFile, false);
doc = lbl.ActiveDocument;
if (dtLabelValue != null)
{
for (int i = 0; i < dtLabelValue.Columns.Count; i++)
{
doc.Variables.FormVariables.Item(dtLabelValue.Columns[i].ColumnName).Value = dtLabelValue.Rows[0][dtLabelValue.Columns[i].ColumnName].ToString(); //给参数传值
}
}
}
if (strLabelExtension.IndexOf("LAB", StringComparison.OrdinalIgnoreCase) >= 0
&& strPrintString == "")
{
doc.PrintDocument(1);
lbl.Quit();
return "OK";
}
if (strLabelExtension.IndexOf("LAB", StringComparison.OrdinalIgnoreCase) >= 0
&& strPrintType == "NET"
&& strPrintString != "")
{
string[] strNet = strPrintString.Split(':');
if (strNet.Length != 2)
{
return "IP:Port NOT Defined, PrintString=" + strPrintString;
}
string strIP = (strNet.Length == 2) ? strNet[0] : "";
string strPort = (strNet.Length == 2) ? strNet[1] : "";
bool bolResult = false;
bolResult = doc.Printer.SwitchTo(strIP, strPort, true);
if (bolResult == false)
{
return "Printer Connected Fail, IP=" + strIP + ", Port" + strPort;
}
doc.PrintDocument(1);
lbl.Quit();
return "OK";
}