zoukankan      html  css  js  c++  java
  • asp.net在word页眉插入条形码

    条形码控件需要引用MSBCODE9.OCX组件。该组件的默认位置是C:Program FilesMicrosoft OfficeOffice122052MSBCODE9.OCX

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Word = Microsoft.Office.Interop.Word;
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Word.Application curWord = null;
                Word.Document curDocument = null;             object mvalue = System.Reflection.Missing.Value;

                curWord = new Microsoft.Office.Interop.Word.Application();

                try
                {
                    string path = @"D:***.doc";
                    object filepath = path;
                    object obj1 = "BARCODE.BarCodeCtrl.1";
                    curDocument = curWord.Documents.Open(ref filepath, ref mvalue, ref mvalue, ref mvalue, ref mvalue, ref mvalue,                     ref mvalue, ref mvalue, ref mvalue, ref mvalue, ref mvalue, ref mvalue, ref mvalue, ref mvalue, ref mvalue,
                        ref mvalue);
                    object range = curWord.ActiveWindow.Selection.Range;
                    curDocument.ActiveWindow.ActivePane.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekCurrentPageHeader;
                    object s = curDocument.ActiveWindow.Selection.InlineShapes.AddOLEControl(ref obj1, ref mvalue).OLEFormat.Object;
                    ((BARCODELib.IBarCodeCtrl)s).Style = 7; ((BARCODELib.IBarCodeCtrl)s).Value = "S45132465789s";
                    curDocument.ActiveWindow.Selection.InlineShapes[1].Width = 300f;
                    curDocument.ActiveWindow.Selection.InlineShapes[1].Height = 70f;
                    curDocument.ActiveWindow.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;
                    curDocument.Save();
                    curDocument.Close(ref mvalue, ref mvalue, ref mvalue);
                    curWord.Quit(ref mvalue, ref mvalue, ref mvalue);
                    curDocument = null;
                    curWord = null;
                }
                catch (Exception ex)
                {
                    curDocument.Close(ref mvalue, ref mvalue, ref mvalue);
                    curWord.Quit(ref mvalue, ref mvalue, ref mvalue);
                    curDocument = null;
                    curWord = null;
                }
            }
        }
    }

  • 相关阅读:

    tomcat 和jboss区别
    python好文章
    CUBRID学习笔记 34 net参数化查询 cubrid教程示例
    CUBRID学习笔记 33 net事务 cubrid教程示例
    CUBRID学习笔记 32 对net的datatable的支持 cubrid教程
    CUBRID学习笔记 31 通过select创建表
    CUBRID学习笔记 30 复制表结构 cubrid教程
    CUBRID学习笔记 29 web管理中文语言文件 CUBRID教程
    CUBRID学习笔记 28 执行sql脚本文件
  • 原文地址:https://www.cnblogs.com/xbzhu/p/5565878.html
Copyright © 2011-2022 走看看