C#调用Bartender 连TXT文件出错 A database with the name "TextfileDatabase" does not exis
目的:在数据库中设定标签格式,及定义的Substring设定值类型。
再通过给定义的文件路径及格式,打印。
版本:9.4
代码如下:
if (!File.Exists(filepath))
{
MessageBox.Show("打印文件不存在!", "警告", MessageBoxButtons.OK);
return;
}
string connstr = "";
try
{
engine = new Engine();
engine.Start();
LabelFormatDocument btFormat = engine.Documents.Open(FormPath);
btFormat.PrintSetup.PrinterName = printName;
// Assign number of identical copies if it is not datasourced.
if (!(printCopies >= 1))
MessageBox.Show("Warning", "Copies must be an integer greater than or equal
to 1.", MessageBoxButtons.OK);
else
btFormat.PrintSetup.IdenticalCopiesOfLabel = printCopies;
//连接txt文件作为数据库
TextFile textFileDB = new TextFile("TextfileDatabase");
textFileDB.FileName = filepath;
btFormat.DatabaseConnections.SetDatabaseConnection(textFileDB);
//取文件名作为数据库域名称
string filename = print_set_header.Rows[0]["FORMAT_NAME"].ToString() ;
filename = filename.Replace(".btw", "");
//根据标签Substring取值类型赋值
for (int i = 0; i < print_set_detail.Rows.Count; i++)
{
//指定文字
if ("T".Equals(print_set_detail.Rows[i]["TYPE"].ToString(),
StringComparison.CurrentCultureIgnoreCase))
{
btFormat.SubStrings[print_set_detail.Rows[i]["VARIABLE"].ToString
()].Value = print_set_detail.Rows[i]["COL"].ToString();
}
else
//数据库字段
{
btFormat.SubStrings[print_set_detail.Rows[i]["VARIABLE"].ToString
()].Value = filename +"."+ Convert.ToInt32(print_set_detail.Rows[i]["COL"]).ToString();
}
}
btFormat.Print();
btFormat.Close(SaveOptions.DoNotSaveChanges);
engine.Stop();
engine.Dispose();
}
catch (PrintEngineException exception)
{
// If the engine is unable to start, a PrintEngineException will be thrown.
MessageBox.Show("Warning", exception.Message, MessageBoxButtons.OK);
//this.Close(); // Close this app. We cannot run without connection to an engine.
return;
}
在以下代码处报错:
btFormat.DatabaseConnections.SetDatabaseConnection(textFileDB);
错误提示为:
A database with the name "TextfileDatabase" does not exist.
再通过给定义的文件路径及格式,打印。
版本:9.4
代码如下:
if (!File.Exists(filepath))
{
MessageBox.Show("打印文件不存在!", "警告", MessageBoxButtons.OK);
return;
}
string connstr = "";
try
{
engine = new Engine();
engine.Start();
LabelFormatDocument btFormat = engine.Documents.Open(FormPath);
btFormat.PrintSetup.PrinterName = printName;
// Assign number of identical copies if it is not datasourced.
if (!(printCopies >= 1))
MessageBox.Show("Warning", "Copies must be an integer greater than or equal
to 1.", MessageBoxButtons.OK);
else
btFormat.PrintSetup.IdenticalCopiesOfLabel = printCopies;
//连接txt文件作为数据库
TextFile textFileDB = new TextFile("TextfileDatabase");
textFileDB.FileName = filepath;
btFormat.DatabaseConnections.SetDatabaseConnection(textFileDB);
//取文件名作为数据库域名称
string filename = print_set_header.Rows[0]["FORMAT_NAME"].ToString() ;
filename = filename.Replace(".btw", "");
//根据标签Substring取值类型赋值
for (int i = 0; i < print_set_detail.Rows.Count; i++)
{
//指定文字
if ("T".Equals(print_set_detail.Rows[i]["TYPE"].ToString(),
StringComparison.CurrentCultureIgnoreCase))
{
btFormat.SubStrings[print_set_detail.Rows[i]["VARIABLE"].ToString
()].Value = print_set_detail.Rows[i]["COL"].ToString();
}
else
//数据库字段
{
btFormat.SubStrings[print_set_detail.Rows[i]["VARIABLE"].ToString
()].Value = filename +"."+ Convert.ToInt32(print_set_detail.Rows[i]["COL"]).ToString();
}
}
btFormat.Print();
btFormat.Close(SaveOptions.DoNotSaveChanges);
engine.Stop();
engine.Dispose();
}
catch (PrintEngineException exception)
{
// If the engine is unable to start, a PrintEngineException will be thrown.
MessageBox.Show("Warning", exception.Message, MessageBoxButtons.OK);
//this.Close(); // Close this app. We cannot run without connection to an engine.
return;
}
在以下代码处报错:
btFormat.DatabaseConnections.SetDatabaseConnection(textFileDB);
错误提示为:
A database with the name "TextfileDatabase" does not exist.
...全文
相关推荐
2024年基于自然的解决方案:中欧案例研究与经验总结报告.docx
2024年基于自然的解决方案:中欧案例研究与经验总结报告.docx
使用SSA(MATLAB)对阿尔茨海默病小鼠模型进行脑电信号分析.zip
1.版本:matlab2014a/2019b/2024b 2.附赠案例数据可直接运行。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。
Special-Comfy-part2.7z.088
ComfyUI专用模型资源分卷压缩包,Special-Comfy-part2系列第088卷。7z分卷格式,单卷900MB,需配合全部分卷解压使用。
高校技术转移办公室人员在成果转化过程中,如何实现科技成果的精准推介与高效转化?.docx
高校技术转移办公室人员在成果转化过程中,如何实现科技成果的精准推介与高效转化?
政府科技管理者如何提升科技成果转化政策落实的精准性?.docx
政府科技管理者如何提升科技成果转化政策落实的精准性?


