qq_21960013 2016-12-20 05:46 采纳率: 0%
浏览 1624

C#调用CodeSoft打印条码 ,未将对象引用设置到对象的实例怎么解决?

public bool PrintMAC(DataTable dtb, string barcode, string Prefix, string SerNum, int ptnum, string model, out string error)
{
Kill("lppa");
model = AppDomain.CurrentDomain.BaseDirectory + model;//取当前应用程序域运行的目录
LabelManager2.ApplicationClass PrintApp = new LabelManager2.ApplicationClass();

    try
    {
        LabelManager2.Document PrintDoc = PrintApp.ActiveDocument;
        PrintDoc = PrintApp.Documents.Open(model, false);
        if (PrintDoc == null)
        {
            error = "模版未找到";
            return false;
        }

        if (!string.IsNullOrEmpty(barcode))
        {
            PrintDoc.Variables.Counters.Item(barcode).Prefix = Prefix;
            PrintDoc.Variables.Counters.Item(barcode).Value = SerNum;
        }

        for (int j = 0; j < dtb.Rows.Count; j++) //行
        {
            for (int i = 0; i < dtb.Columns.Count; i++) //列
            {
                try
                {
                    string col = dtb.Columns[i].ColumnName.ToString();
                    string txt = dtb.Rows[j][col].ToString();
                    PrintDoc.Variables.FormVariables.Item(col).Value = txt;
                }
                catch (Exception ex)
                {
                    error = ex.Message;
                    return false;
                }
            }
            PrintDoc.PrintDocument(1);

        }
        error = "打印成功";
        return true;

    }
    catch (Exception ex)
    {
        error = ex.Message;
        return false;
    }
    finally
    {
        PrintApp.Documents.CloseAll(false);
        PrintApp.Quit();
    }

}
  • 写回答

1条回答

  • dabocaiqq 2016-12-31 09:35
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿