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 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示