Microsoft Word标签打印实用程序问题

时间:2013-08-05 10:36:34

标签: c# .net ms-word

目前我正在使用Microsoft Word Label Printing Utility从我的.NET应用程序中打印标签。我使用以下代码打印标签。

            Word.Application oWord;
            Word._Document oDoc;

            oDoc = oWord.Documents.Add();
            var a = oWord.MailingLabel.CreateNewDocument("30 Per Page", "", Type.Missing, false, Type.Missing, Type.Missing, Type.Missing);
            oWord.Visible = false;
            var table = a.Content.ConvertToTable().Tables[1];
            var innertable = table.Columns[1].Cells[1].Range.ConvertToTable();
            innertable.Columns[1].Cells[1].Range.Bold = 1;

            innertable.Columns[1].Cells[1].Range.Text = "sdadad";
            innertable.Columns[1].Cells[1].Range.Font.Bold = 1;
            innertable.Columns[1].Cells[1].Range.Font.Color = Word.WdColor.wdColorBlue;
            innertable.Columns[1].Cells[1].Range.Font.Size = 15F;
            innertable.Columns[1].Cells[1].Range.Font.Name = "Verdana";
            innertable.Rows.Add();
            innertable.Columns[1].Cells[2].Range.Text = "fsdfsdfsdf";
            innertable.Columns[1].Cells[2].Range.Font.Bold = 0;
            innertable.Columns[1].Cells[2].Range.Font.Color = Word.WdColor.wdColorBrown;
            innertable.Columns[1].Cells[2].Range.Font.Size = 12F;
            innertable.Columns[1].Cells[2].Range.Font.Name = "Segoe UI";

            var docs=oWord.Documents;
            oWord.Visible = true;

现在的问题是这里创建了两个文档。但是我只希望打开标签文件。

提前非常感谢你...... !!

2 个答案:

答案 0 :(得分:0)

请删除以下行:

Word._Document oDoc;
oDoc = oWord.Documents.Add();

,因为他们在Word应用程序中创建新的标准文档。您不要在代码中的任何位置使用它,因此您似乎不需要它。

修改我认为在没有打开任何其他文档的情况下添加MailingLabel document是不可能的。因此,另一个建议是在创建MailingLabel后关闭oDoc document。请尝试以下方法:

//after this line
oWord.Visible = false;
//try to add
oDoc.Close();

答案 1 :(得分:0)

我已使用以下行手动关闭了我的标准文档:

oDoc.Close();

谢谢...... !!