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;
                }
            }
        }
    }

  • 相关阅读:
    AD 文档信息设置和制作模板
    用AT命令调试调制解调器
    语音AT命令参考
    传真AT指令部分(参考)
    传真调制解调器
    knockout+weui+zepto
    20171028随手记
    20171027随记
    一些简单又坑人的无聊使用
    ReadWrite,日志,输入文本
  • 原文地址:https://www.cnblogs.com/xbzhu/p/5565878.html
Copyright © 2011-2022 走看看