Substring
I want to print multiple 2 column labels with different substring data, in one button click. How it is possible through .net programmatically..?
Code not correct. But this is my Idea...
Engine btEngine = new Engine();
btEngine.Start();
LabelFormatDocument btFormat = btEngine.Documents.Open(@"c:\MyLabel.btw");
[indent]btFormat.PageSetup.LabelRows = 1;
btFormat.PageSetup.LabelColumns = 2;
btFormat.SubStrings["Filed1"].Value = "Sony";
btFormat.SubStrings["Field2"].Value = "852154996";
btFormat.SubStrings["Filed1"].Value = "Panasonic";
btFormat.SubStrings["Field2"].Value = "989784564";
btFormat.SubStrings["Filed1"].Value = "Samsung";
btFormat.SubStrings["Field2"].Value = "4582178985";
btFormat.SubStrings["Filed1"].Value = "LG";
btFormat.SubStrings["Field2"].Value = "74128847471";[/indent]
btFormat.Print();
btEngine.Stop();
Normally, It is print only last data at 1 time
That means it is print only LG data..
But I want print all these different data in 2 Rows and 2 columns in a single button click.
That means, Totally I want 4 Labels with different data in 2 columns.
How It is poosible.. Please reply..
Thanks
Code not correct. But this is my Idea...
Engine btEngine = new Engine();
btEngine.Start();
LabelFormatDocument btFormat = btEngine.Documents.Open(@"c:\MyLabel.btw");
[indent]btFormat.PageSetup.LabelRows = 1;
btFormat.PageSetup.LabelColumns = 2;
btFormat.SubStrings["Filed1"].Value = "Sony";
btFormat.SubStrings["Field2"].Value = "852154996";
btFormat.SubStrings["Filed1"].Value = "Panasonic";
btFormat.SubStrings["Field2"].Value = "989784564";
btFormat.SubStrings["Filed1"].Value = "Samsung";
btFormat.SubStrings["Field2"].Value = "4582178985";
btFormat.SubStrings["Filed1"].Value = "LG";
btFormat.SubStrings["Field2"].Value = "74128847471";[/indent]
btFormat.Print();
btEngine.Stop();
Normally, It is print only last data at 1 time
That means it is print only LG data..
But I want print all these different data in 2 Rows and 2 columns in a single button click.
That means, Totally I want 4 Labels with different data in 2 columns.
How It is poosible.. Please reply..
Thanks
0
-
Shotaro Ito
★ BarTender Hero ★
Hi Jiji,
With SubStrings Value method you cannot print two or more records, as setting value just overwrites previous value before print.
What you can do is, design label format to use text database (CSV etc).
From C# app, create temp CSV File with desired records, apply the file by SetDatabaseConnection method.
This way you can print multiple records in one job, so it will take multi-column labels.
[code] // Start the BarTender print engine.
btEngine.Start();
// Create an instance of TextFile
TextFile textFile = new TextFile("TextfileDatabase");
// Provide a path to the text file.
textFile.FileName = @"C:\TextfileDatabase.txt";
// Initialize the format document
// (create a format with query prompts to use this example).
LabelFormatDocument btFormat = btEngine.Documents.Open(@"C:\FormatWithQueryPrompts.btw");
// Set the database connection created above.
btFormat.DatabaseConnections.SetDatabaseConnection(textFile);
// Print the format.
btFormat.Print();
[/code]0 -
Thanks Shotaro.
[b]How can I design label format to use text database (CSV etc). And in text file how can I place data.?[/b]
[indent]With the help of BarTender Software I created one Label.
First I connected to my database and drag one field to Label and Saved it.
But Then, I don't know, in text file which order I want to place data.
I just put some data separated by comma. But after running c# code it is showing the error "Database types do not match"
[/indent]
Can you please give me the procedure in detail.0 -
Shotaro Ito
★ BarTender Hero ★
Hi Jiji,
First you need to create a label format which has CSV data connection.
Say you have a text file like this: ("C:\sample.csv")
[code]"FNAME","LNAME","DOB"
"Sam","Sampleton","1962/07/03"
"Samir","Samproski","1965/01/24"[/code]
first line has list of field names (each fields are quoted by ""), following lines are 2 records of dummy data (and so on.)
Following [url="http://www.seagullscientific.com/aspx/training-video-(reading-data-from-database).aspx"]how to create excel database connection[/url], you can create Text database connection to the text file, with select Delimitation type as "Mixed Quote and Comma" (which means CSV) and First record is "header" to [Yes].
Associate some text's datasource to database fields, and print preview to see 2 labels will be printed.
Save the format (such as "C:\FMT1.BTW")
In .net SDK, you can assign text database by SetDatabaseConnection() method like below:
[code]
// Open format at same folder as executable
btFormat = btEngine.Documents.Open(Application.StartupPath + @"\FMT1.btw");
//btFormat.PrintSetup.PrinterName("Zebra TLP3844-Z"); // specify printer
// Prepare data (you can be more creative.)
string buf = "";
buf += "\"FNAME\",\"LNAME\",\"DOB\"\r\n"; // header
buf += "\"Steven\",\"Jobs\",\"1955/02/24\"\r\n"; //record 1
buf += "\"Stephen\",\"Wozniak\",\"1950/08/11\"\r\n";
buf += "\"John\",\"Sculley\",\"1939/04/06\"\r\n";
buf += "\"Gilbert\",\"Amerio\",\"1943/03/01\"\r\n";
// Create text database as a temporary file
string tmpFile = Path.GetTempFileName();
File.WriteAllText (tmpFile, buf);
// Assign the text database to curtent format's primary database
Seagull.BarTender.Print.Database.TextFile tf = new Seagull.BarTender.Print.Database.TextFile(btFormat.DatabaseConnections[0].Name);
tf.FileName = tmpFile;
btFormat.DatabaseConnections.SetDatabaseConnection(tf);
btFormat.PrintSetup.ReloadTextDatabaseFields = true; // Fix when field order is different from design time
// Print
btFormat.Print();
// Delete text database
File.Delete(tmpFile);[/code]
I've posted a [url="http://seagullscientific.invisionzone.com/index.php?/topic/525-sample-code-create-and-assign-csv-database/"]sample project[/url] so please check that.0
Please sign in to leave a comment.
Comments
3 comments