南通最专业的开锁公司 南通最好的开锁公司 君威遥控器电池 君威专用汽车钥匙电池雷诺科雷傲汽车钥匙遥控器电池更换方法 南通开锁公司电话_南通修锁 换锁芯 开汽车锁 崇川区 港闸区 如皋 如东开锁 南通开锁公司电话 南通金钥匙开锁服务部-专业开修锁 换锁芯(正规公安工商备案) 南通开锁公司电话 南通开锁公司修锁 装锁电话|崇川区开锁|港闸区开锁 led吸顶灯光源 吸顶灯32w 吸顶灯 灯管 吸顶灯 节能灯泡 led吸顶灯灯泡 三头吸顶灯 led吸顶灯灯管 欧普圆形吸顶灯 55w吸顶灯 吸顶灯光源 旅游壶 真空保温 汉方养生壶 美的电热水壶15s08a2 半球牌电饭煲 美的 mg123-d hd2 飞科 三洋洗衣机全自动 新安怡 学饮杯 黑苦荞黄酮软胶囊 苦荞糖安胶囊 五彩凉山苦荞茶 苦荞茶250g 全胚芽黑苦荞茶500 内蒙特产苦荞茶 富贵康苦荞茶 苦荞面包邮 正中苦荞茶包邮 正中苦荞茶 包邮 苦荞香茶西部 苦荞香茶 西部 轩庆苦荞玫瑰鲜花饼 苦荞真空 苦荞500克 苦荞茶120 苦荞 真空 0.02安全套包邮0.2大力马鱼线0.4mm0.4鱼线0.5l氮纤维高压瓶007sh充电器007电子请柬00高达xn-raiser01102400018401背囊0-25微米千分尺03g101系列全套图集0-3个月婴儿连体哈衣05-08本田奥德赛05ffc23套机05版河南动感地带0603贴片电阻包06年款英派斯06斯巴鲁森林人cd机07军衔07军用水壶07款福克斯两厢07数码迷彩07速腾大灯总成 泰好大门锁 泰好豪华大门锁 cei超b级锁芯 玻璃橱门锁 指纹锁耶鲁4109 耶鲁凯特曼指纹锁 防盗挂锁包邮 包挂锁 包梁挂锁 新君威门锁 新君威门锁扣 指纹锁木门 太空铝黑色门锁 泰好浴室铜门锁 浴室门锁不锈钢 1178冷库门锁 南通配新桑塔纳2000 3000 时代超人 志俊汽车钥匙_配帕桑塔纳钥匙遥控器_帕萨特钥匙全丢重配崇川区 南通配宝来汽车钥匙_配宝来遥控器_宝来钥匙全丢如皋 南通配帕萨特汽车钥匙_配帕萨特遥控器_帕萨特钥匙全丢通州 南通配凯越汽车钥匙_配凯越遥控器_凯越钥匙全丢如东

  • 格子衬衣女 长袖 秋
  • t男恤 短袖 韩版包邮
  • 男士职业衬衫
  • 衬衫 女 长袖点点
  • 衬衫 素色 男 宽松 休闲
  • 职场气质衬衫女
  • t恤男短袖加大码不掉色
  • 帅T 小西装
  • 裤子棕色长裤男
  • 衬衣 女 灯芯绒
  • 衬衣 女商务
  • 女士职业衬衫短袖
  • 休闲裤 男 修身
  • jamesearl纯棉休闲长裤
  • 占姆士女式长袖衬衫
  • 男黑色商务休闲棉长裤
  • 女士长袖衬衫
  • 男士绿色休闲长裤
  • 全棉短袖衬衫 男 薄
  • 女士长袖纯棉衬衫
  • 秋裤男直筒
  • 马自达3汽车挂件吊坠饰品 高档琉璃汽车挂饰品蒙迪欧致胜汽车挂件吊坠饰品 高档琉璃汽车挂饰品 启辰D50汽车挂件吊坠饰品 高档琉璃汽车挂饰品起亚K2汽车挂件吊坠饰品 高档琉璃汽车挂饰品索纳塔汽车挂件吊坠饰品 高档琉璃汽车挂饰品天籁汽车挂件吊坠饰品 高档琉璃汽车挂饰品 天语SX4汽车挂件吊坠饰品 高档琉璃汽车挂饰品英朗GT汽车挂件吊坠饰品 高档琉璃汽车挂饰品英伦SC7汽车挂件吊坠饰品 高档琉璃汽车挂饰品自由舰汽车挂件吊坠饰品 高档琉璃汽车挂饰品雨燕汽车挂件吊坠饰品 高档琉璃汽车挂饰品雪佛兰迈锐宝汽车挂件吊坠饰品 高档琉璃汽车挂饰品

    秋冬季现代瑞纳 宝马5系 帕萨特 日产骐达专用汽车毛绒方向盘套 江苏省盐城市地图2014 最新版 江苏省卫星地图2014 最新版 百度地图-谷歌地图-中国地图-北京地图-搜狗地图google地图 广本凌派汽车座垫 凌派秋冬季汽车坐垫 四季通用 长安福特福克斯油耗详解 宝来汽车遥控钥匙电池 更换方法 图解宝来遥控钥匙的电池换法 宝骏630车钥匙遥控器电池更换步骤 更换方法 迈腾车钥匙电池 迈腾更换遥控器电池详解逍客汽车钥匙电池 遥控器逍客智能钥匙的电池更换步骤 新天籁智能遥控钥匙电池 新天籁智能钥匙如何更换纽扣电池 golf6 汽车钥匙遥控器换电池 图解高尔夫6遥控钥匙的电池换法 长安福特福克斯加速时间详解[图] 福克斯汽车钥匙电池 福克斯钥匙电池更换作业 Q5车钥匙更换电池方法 图解新凯越车钥匙更换电池
  • 汽车坐垫 可爱
  • wrc汽车坐垫
  • 汽车坐垫套四季通用
  • 明锐冰丝 汽车坐套
  • 骐达汽车脚垫全包围
  • 三菱蓝瑟汽车坐垫
  • 捷达汽车脚垫 3d
  • 奥迪S7坐垫
  • 别克荣御坐垫
  • Jeep指南者坐垫
  • 力帆320坐垫
  • 路虎卫士坐垫
  • 双龙爱腾坐垫
  • 斯柯达Yeti坐垫
  • 现代途胜坐垫
  • 一汽威乐坐垫
  • 哈飞路宝汽车坐垫
  • 吉利远景汽车坐垫
  • 吉利全球鹰汽车坐垫
  • 房门锁执手锁 防盗挂锁
  • 运动短裤
  • 短裤 男
  • 半裙
  • 手工拖鞋鞋底
  • iphone4皮套 手机套
  • 机油滤清器扳手工具
  • 桑塔纳3000机油
  • 家居摆件现代
  • 玻璃摆件
  • 瓷器摆件
  • 马到成功摆件
  • 高档瓷器摆件
  • 宝马山地自行车包邮
  • 根雕工艺品摆件
  • 家居摆件吊脚娃娃
  • 泰国佛像摆件工艺品
  • 美利达儿童自行车
  • 天鹅摆件结婚
  • 龙龟摆件纯铜
  • 金摆件聚宝盆
  • 亲子自行车 女式
  • 客厅卧室装饰摆件
  • 贵宾狗摆件
  • 木摆件
  • 羚羊头摆件
  • 招财兔摆件
  • 自行车前包
  • 牛仔短裤
  • 短裤 男 休闲
  • 高腰短裤
  • 夏季短裤
  • 蕾丝短裤
  • 连体短裤
  • 裙裤
  • 裤裙
  • 拖鞋 海外
  • 拖鞋 浴室
  • 拖鞋 防滑
  • 拖 鞋 男
  • 拖鞋 女
  • 浴室拖鞋
  • 家居拖鞋
  • 凉拖鞋
  • 夏天拖鞋
  • 香菇丸
  • 韩国饮料
  • 打草绳小松打草绳二手挖掘机小松 小松割灌机配件 钢木书桌办公桌钢木桌玻璃杯子水壶钢化玻璃水壶钢木办公桌钢木电脑桌进口玻璃水壶玻璃水成份防冻玻璃水包邮防冻玻璃水车用 环保果皮箱环保垃圾袋环保垃圾桶小松120-6常州小松割草机小松打草头小松割灌机小松割灌机配件 咖啡厅员工制服_咖啡厅服务员制服_西餐咖啡服务员制服_咖啡馆制服_咖啡店西餐
  • 5号充电电池8节套装
  • 5-7号电池充电器
  • 充电电池5号正品
  • 可充电电池5号
  • 7号充电电池批发
  • 7号电池包邮
  • 1.5v充电电池5号
  • 5号充电器电池免邮
  • 双鹿电池5号正品
  • 双鹿9v电池
  • 双鹿电池批发
  • 双鹿7号电池
  • 双鹿1号电池
  • 双鹿碱性电池
  • 三星s4电池原装正品
  • 三星s4原装电池后盖
  • n7100原装电池
  • 小米2s原装电池
  • galaxy s4大容量电池
  • galaxy s4原装电池
  • galaxy s3电池
  • galaxy nexus电池
  • 三星galaxy s4电池后盖
  • 品胜小米2s电池
  • 品胜手机电池
  • 小米2a电池品胜
  • 背夹电池iphone4s
  • note2背夹电池
  • 三星s4背夹电池皮套
  • 自行车fixedgear 自行车眼镜 近视 婴儿推车小自行车 自行车骑行眼镜风镜 钻石自行车 山地自行车立管 led自行车气嘴专用灯 三鼎自行车坐椅儿童 自行车线管 金镶玉玉器挂件 自行车脚踏双轴承 铬钼钢架自行车 邦德自行车女式 山地公路自行车 自行车骑行手电筒 自行车灯架 灯夹包邮 自行车水壶支架 自行车 组装 mosso 自行车载mp3 26自行车 男生单车 自行车 折叠 复古 giant山地车 自行车 炫彩自行车 七彩马亲子自行车 ucc山地车 自行车 贝嘉琦 女孩自行车 zxc自行车配件码表 自行车前置安全椅 女童自行车 小龙哈比 自行车碳纤维垫圈 自行车骑行用品 装饰木板板材 美式壁挂装饰 家具装饰配件 衣服装饰亮片 婚礼礼品实用 公司开业庆典礼品 婴儿衣柜 儿童欧式公主床 床围栏护栏嵌入式 床靠背套 派克圆珠笔芯 卧室台灯床头灯现代 个性笔袋 派克im签字笔 彩色铅笔包邮 派克宝珠笔芯 派克笔芯正品 百乐摩可擦笔笔芯 斑马油笔 微型钢笔钓鱼竿 电子教鞭遥控笔 镭射灯激光笔 彩色水笔芯 黑色水笔笔芯 公爵宝珠笔芯 touch3代马克笔 韩国文具笔包邮 水溶性彩色铅笔 马可 sgp触控笔 礼品创意笔筒 铂金 项链 pt950 男 老竹笔筒 竹雕笔筒 六福珠宝铂金手镯 8.9寸笔记本电脑 三菱签字笔1.0 华硕游戏笔记本 插座面板

    WordOperate.cs

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.IO;
    using Microsoft.Win32;
    using Microsoft.Office.Interop.Word;
    using System.Net;
    using System.Web;
    using System.Text.RegularExpressions;

    namespace OfficeOperate
    {
        public class WordOperate
        {

            #region 新建Word文档
            /// <summary>
            /// 动态生成Word文档并填充内容
            /// </summary>
            /// <param name="dir">文档目录</param>
            /// <param name="fileName">文档名</param>
            /// <returns>返回自定义信息</returns>
            public static bool CreateWordFile(string dir, string fileName)
            {
                try
                {
                    Object oMissing = System.Reflection.Missing.Value;

                    if (!Directory.Exists(dir))
                    {
                        //创建文件所在目录
                        Directory.CreateDirectory(dir);
                    }
                    //创建Word文档(Microsoft.Office.Interop.Word)
                    Microsoft.Office.Interop.Word._Application WordApp = new Application();
                    WordApp.Visible = true;
                    Microsoft.Office.Interop.Word._Document WordDoc = WordApp.Documents.Add(
                        ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                                    
                    //保存
                    object filename = dir + fileName;
                    WordDoc.SaveAs(ref filename, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                        ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                        ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                    WordDoc.Close(ref oMissing, ref oMissing, ref oMissing);
                    WordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
                    return true;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);
                    return false;
                }
            }

            #endregion 新建Word文档

            #region 给word文档添加页眉页脚
            /// <summary>
            /// 给word文档添加页眉
            /// </summary>
            /// <param name="filePath">文件名</param>
            /// <returns></returns>
            public static bool AddPageHeaderFooter(string filePath)
            {
                try
                {
                    Object oMissing = System.Reflection.Missing.Value;
                    Microsoft.Office.Interop.Word._Application WordApp = new Application();
                    WordApp.Visible = true;
                    object filename = filePath;
                    Microsoft.Office.Interop.Word._Document WordDoc = WordApp.Documents.Open(ref filename, ref oMissing,
                        ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                        ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

                    ////添加页眉方法一:
                    //WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView;
                    //WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader;
                    //WordApp.ActiveWindow.ActivePane.Selection.InsertAfter( "**公司" );//页眉内容

                    ////添加页眉方法二:
                    if (WordApp.ActiveWindow.ActivePane.View.Type == WdViewType.wdNormalView ||
                        WordApp.ActiveWindow.ActivePane.View.Type == WdViewType.wdOutlineView)
                    {
                        WordApp.ActiveWindow.ActivePane.View.Type = WdViewType.wdPrintView;
                    }
                    WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekCurrentPageHeader;
                    WordApp.Selection.HeaderFooter.LinkToPrevious = false;
                    WordApp.Selection.HeaderFooter.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
                    WordApp.Selection.HeaderFooter.Range.Text = "页眉内容";
                    
                    WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekCurrentPageFooter;
                    WordApp.Selection.HeaderFooter.LinkToPrevious = false;
                    WordApp.Selection.HeaderFooter.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
                    WordApp.ActiveWindow.ActivePane.Selection.InsertAfter("页脚内容");

                    //跳出页眉页脚设置
                    WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument;

                    //保存
                    WordDoc.Save();
                    WordDoc.Close(ref oMissing, ref oMissing, ref oMissing);
                    WordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
                    return true;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);
                    return false;
                }
            }
            #endregion 给word文档添加页眉页脚

            #region 设置文档格式并添加文本内容
            /// <summary>
            /// 设置文档格式并添加文本内容
            /// </summary>
            /// <param name="filePath">文件名</param>
            /// <returns></returns>
            public static bool AddContent(string filePath)
            {
                try
                {
                    Object oMissing = System.Reflection.Missing.Value;
                    Microsoft.Office.Interop.Word._Application WordApp = new Application();
                    WordApp.Visible = true;
                    object filename = filePath;
                    Microsoft.Office.Interop.Word._Document WordDoc = WordApp.Documents.Open(ref filename, ref oMissing,
                        ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                        ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

                    //设置居左
                    WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

                    //设置文档的行间距
                    WordApp.Selection.ParagraphFormat.LineSpacing = 15f;
                    //插入段落
                    //WordApp.Selection.TypeParagraph();
                    Microsoft.Office.Interop.Word.Paragraph para;
                    para = WordDoc.Content.Paragraphs.Add(ref oMissing);
                    //正常格式
                    para.Range.Text = "This is paragraph 1";
                    //para.Range.Font.Bold = 2;
                    //para.Range.Font.Color = WdColor.wdColorRed;
                    //para.Range.Font.Italic = 2;
                    para.Range.InsertParagraphAfter();

                    para.Range.Text = "This is paragraph 2";
                    para.Range.InsertParagraphAfter();

                    //插入Hyperlink
                    Microsoft.Office.Interop.Word.Selection mySelection = WordApp.ActiveWindow.Selection;
                    mySelection.Start = 9999;
                    mySelection.End = 9999;
                    Microsoft.Office.Interop.Word.Range myRange = mySelection.Range;
                                    
                    Microsoft.Office.Interop.Word.Hyperlinks myLinks = WordDoc.Hyperlinks;
                    object linkAddr = @"http://www.cnblogs.com/lantionzy";
                    Microsoft.Office.Interop.Word.Hyperlink myLink = myLinks.Add(myRange, ref linkAddr,
                        ref oMissing);
                    WordApp.ActiveWindow.Selection.InsertAfter("\n");
                  
                    //落款
                    WordDoc.Paragraphs.Last.Range.Text = "文档创建时间:" + DateTime.Now.ToString();
                    WordDoc.Paragraphs.Last.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;

                    //保存
                    WordDoc.Save();
                    WordDoc.Close(ref oMissing, ref oMissing, ref oMissing);
                    WordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
                    return true;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);
                    return false;
                }
            }

            #endregion 设置文档格式并添加文本内容

            #region 文档中添加图片
            /// <summary>
            /// 文档中添加图片
            /// </summary>
            /// <param name="filePath">word文件名</param>
            /// <param name="picPath">picture文件名</param>
            /// <returns></returns>
            public static bool AddPicture(string filePath, string picPath)
            {
                try
                {
                    Object oMissing = System.Reflection.Missing.Value;
                    Microsoft.Office.Interop.Word._Application WordApp = new Application();
                    WordApp.Visible = true;
                    object filename = filePath;
                    Microsoft.Office.Interop.Word._Document WordDoc = WordApp.Documents.Open(ref filename, ref oMissing,
                        ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                        ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

                    //移动光标文档末尾
                    object count = WordDoc.Paragraphs.Count;
                    object WdLine = Microsoft.Office.Interop.Word.WdUnits.wdParagraph;
                    WordApp.Selection.MoveDown(ref WdLine, ref count, ref oMissing);//移动焦点
                    WordApp.Selection.TypeParagraph();//插入段落

                    object LinkToFile = false;
                    object SaveWithDocument = true;
                    object Anchor = WordDoc.Application.Selection.Range;
                    WordDoc.Application.ActiveDocument.InlineShapes.AddPicture(picPath, ref LinkToFile, ref SaveWithDocument, ref Anchor);

                    //保存
                    WordDoc.Save();
                    WordDoc.Close(ref oMissing, ref oMissing, ref oMissing);
                    WordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
                    return true;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);
                    return false;
                }
            }
            #endregion 文档中添加图片

            #region 表格处理(插入表格、设置格式、填充内容)
            /// <summary>
            /// 表格处理
            /// </summary>
            /// <param name="filePath">word文件名</param>
            /// <returns></returns>
            public static bool AddTable(string filePath)
            {
                try
                {
                    Object oMissing = System.Reflection.Missing.Value;
                    Microsoft.Office.Interop.Word._Application WordApp = new Application();
                    WordApp.Visible = true;
                    object filename = filePath;
                    Microsoft.Office.Interop.Word._Document WordDoc = WordApp.Documents.Open(ref filename, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                        ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

                    //插入表格
                    Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables.Add(WordApp.Selection.Range, 12, 3, ref oMissing, ref oMissing);
                    //设置表格
                    newTable.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleThickThinLargeGap;
                    newTable.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
                    newTable.Columns[1].Width = 100f;
                    newTable.Columns[2].Width = 220f;
                    newTable.Columns[3].Width = 105f;
                    
                    //填充表格内容
                    newTable.Cell(1, 1).Range.Text = "我的简历";
                    //设置单元格中字体为粗体
                    newTable.Cell(1, 1).Range.Bold = 2;

                    //合并单元格
                    newTable.Cell(1, 1).Merge(newTable.Cell(1, 3));
                    
                    //垂直居中
                    WordApp.Selection.Cells.VerticalAlignment = Microsoft.Office.Interop.Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                    //水平居中
                    WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;

                    //填充表格内容
                    newTable.Cell(2, 1).Range.Text = "座右铭:...";
                    //设置单元格内字体颜色
                    newTable.Cell(2, 1).Range.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorDarkBlue;
                    //合并单元格
                    newTable.Cell(2, 1).Merge(newTable.Cell(2, 3));
                    WordApp.Selection.Cells.VerticalAlignment = Microsoft.Office.Interop.Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;

                    //填充表格内容
                    newTable.Cell(3, 1).Range.Text = "姓名:";
                    newTable.Cell(3, 2).Range.Text = "雷鑫";
                    //纵向合并单元格
                    newTable.Cell(3, 3).Select();
                    //选中一行
                    object moveUnit = Microsoft.Office.Interop.Word.WdUnits.wdLine;
                    object moveCount = 3;
                    object moveExtend = Microsoft.Office.Interop.Word.WdMovementType.wdExtend;
                    WordApp.Selection.MoveDown(ref moveUnit, ref moveCount, ref moveExtend);
                    WordApp.Selection.Cells.Merge();

                    //表格中插入图片
                    string pictureFileName = System.IO.Directory.GetCurrentDirectory() + @"\picture.jpg";
                    object LinkToFile = false;
                    object SaveWithDocument = true;
                    object Anchor = WordDoc.Application.Selection.Range;
                    WordDoc.Application.ActiveDocument.InlineShapes.AddPicture(pictureFileName, ref LinkToFile, ref SaveWithDocument, ref Anchor);
                    //图片宽度
                    WordDoc.Application.ActiveDocument.InlineShapes[1].Width = 100f;
                    //图片高度
                    WordDoc.Application.ActiveDocument.InlineShapes[1].Height = 100f;
                    //将图片设置为四周环绕型
                    Microsoft.Office.Interop.Word.Shape s = WordDoc.Application.ActiveDocument.InlineShapes[1].ConvertToShape();
                    s.WrapFormat.Type = Microsoft.Office.Interop.Word.WdWrapType.wdWrapSquare;

                    newTable.Cell(12, 1).Range.Text = "备注:";
                    newTable.Cell(12, 1).Merge(newTable.Cell(12, 3));
                    //在表格中增加行
                    WordDoc.Content.Tables[1].Rows.Add(ref oMissing);

                    //保存
                    WordDoc.Save();
                    WordDoc.Close(ref oMissing, ref oMissing, ref oMissing);
                    WordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
                    return true;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);
                    return false;
                }
            }
            #endregion #region 表格处理

            #region 把Word文档转化为Html文件
            /// <summary>
            /// 把Word文档转化为Html文件
            /// </summary>
            /// <param name="wordFileName">word文件名</param>
            /// <param name="htmlFileName">要保存的html文件名</param>
            /// <returns></returns>
            public static bool WordToHtml(string wordFileName, string htmlFileName)
            {
                try
                {
                    Object oMissing = System.Reflection.Missing.Value;
                    Microsoft.Office.Interop.Word._Application WordApp = new Application();
                    WordApp.Visible = true;
                    object filename = wordFileName;
                    Microsoft.Office.Interop.Word._Document WordDoc = WordApp.Documents.Open(ref filename, ref oMissing,
                        ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                        ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

                   // Type wordType = WordApp.GetType();
                    // 打开文件
                    Type docsType = WordApp.Documents.GetType();
                    // 转换格式,另存为
                    Type docType = WordDoc.GetType();
                    object saveFileName = htmlFileName;
                    docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, WordDoc,
                        new object[] { saveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML });

                    #region 其它格式:
                    ///wdFormatHTML
                    ///wdFormatDocument
                    ///wdFormatDOSText
                    ///wdFormatDOSTextLineBreaks
                    ///wdFormatEncodedText
                    ///wdFormatRTF
                    ///wdFormatTemplate
                    ///wdFormatText
                    ///wdFormatTextLineBreaks
                    ///wdFormatUnicodeText
                    // 退出 Word
                    //wordType.InvokeMember( "Quit", System.Reflection.BindingFlags.InvokeMethod,
                    //    null, WordApp, null );
                    #endregion

                    //保存
                    WordDoc.Save();
                    WordDoc.Close(ref oMissing, ref oMissing, ref oMissing);
                    WordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
                    return true;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);
                    return false;
                }
            }
            #endregion 把Word文档转化为Html文件
            
            #region word中添加新表
            /// <summary>
            /// word中添加新表
            /// </summary>
            public static void AddTable()
            {
                object oMissing = System.Reflection.Missing.Value;
                Microsoft.Office.Interop.Word._Application WordApp;
                Microsoft.Office.Interop.Word._Document WordDoc;
                WordApp = new Microsoft.Office.Interop.Word.Application();
                WordApp.Visible = true;
                WordDoc = WordApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);

                object start = 0;
                object end = 0;
                Microsoft.Office.Interop.Word.Range tableLocation = WordDoc.Range(ref start, ref end);
                WordDoc.Tables.Add(tableLocation, 3, 4, ref oMissing, ref oMissing);//3行4列的表
            }
            #endregion word中添加新表

            #region 在表中插入新行

            /// <summary>
            /// 在表中插入新的1行
            /// </summary>
            public static void AddRow()
            {
                object oMissing = System.Reflection.Missing.Value;
                Microsoft.Office.Interop.Word._Application WordApp;
                Microsoft.Office.Interop.Word._Document WordDoc;
                WordApp = new Microsoft.Office.Interop.Word.Application();
                WordApp.Visible = true;
                WordDoc = WordApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);

                object start = 0;
                object end = 0;
                Microsoft.Office.Interop.Word.Range tableLocation = WordDoc.Range(ref start, ref end);
                WordDoc.Tables.Add(tableLocation, 3, 4, ref oMissing, ref oMissing);

                Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables[1];
                object beforeRow = newTable.Rows[1];
                newTable.Rows.Add(ref beforeRow);
            }
            #endregion

            #region 合并单元格
            /// <summary>
            /// 合并单元格
            /// </summary>
            public static void CombinationCell()
            {
                object oMissing = System.Reflection.Missing.Value;
                Microsoft.Office.Interop.Word._Application WordApp;
                Microsoft.Office.Interop.Word._Document WordDoc;
                WordApp = new Microsoft.Office.Interop.Word.Application();
                WordApp.Visible = true;
                WordDoc = WordApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);

                object start = 0;
                object end = 0;
                Microsoft.Office.Interop.Word.Range tableLocation = WordDoc.Range(ref start, ref end);
                WordDoc.Tables.Add(tableLocation, 3, 4, ref oMissing, ref oMissing);

                Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables[1];
                object beforeRow = newTable.Rows[1];
                newTable.Rows.Add(ref beforeRow);

                Microsoft.Office.Interop.Word.Cell cell = newTable.Cell(2, 1);//2行1列合并2行2列为一起
                cell.Merge(newTable.Cell(2, 2));
                //cell.Merge( newTable.Cell( 1, 3 ) );
            }
            #endregion 合并单元格

            #region 分离单元格
            /// <summary>
            /// 分离单元格
            /// </summary>
            public static void SeparateCell()
            {
                object oMissing = System.Reflection.Missing.Value;
                Microsoft.Office.Interop.Word._Application WordApp;
                Microsoft.Office.Interop.Word._Document WordDoc;
                WordApp = new Microsoft.Office.Interop.Word.Application();
                WordApp.Visible = true;
                WordDoc = WordApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);

                object start = 0;
                object end = 0;
                Microsoft.Office.Interop.Word.Range tableLocation = WordDoc.Range(ref start, ref end);
                WordDoc.Tables.Add(tableLocation, 3, 4, ref oMissing, ref oMissing);

                Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables[1];
                object beforeRow = newTable.Rows[1];
                newTable.Rows.Add(ref beforeRow);

                Microsoft.Office.Interop.Word.Cell cell = newTable.Cell(1, 1);
                cell.Merge(newTable.Cell(1, 2));

                object Rownum = 2;
                object Columnnum = 2;
                cell.Split(ref Rownum, ref  Columnnum);
            }
            #endregion 分离单元格

            #region 通过段落控制插入
            /// <summary>
            /// 通过段落控制插入Insert a paragraph at the beginning of the document.
            /// </summary>
            public static void InsertParagraph()
            {
                object oMissing = System.Reflection.Missing.Value;
                //object oEndOfDoc = "\\endofdoc";
                //endofdoc is a predefined bookmark

                //Start Word and create a new document.
                Microsoft.Office.Interop.Word._Application WordApp;
                Microsoft.Office.Interop.Word._Document WordDoc;
                WordApp = new Microsoft.Office.Interop.Word.Application();
                WordApp.Visible = true;

                WordDoc = WordApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);

                //Insert a paragraph at the beginning of the document.
                Microsoft.Office.Interop.Word.Paragraph oPara1;
                oPara1 = WordDoc.Content.Paragraphs.Add(ref oMissing);
                oPara1.Range.Text = "Heading 1";
                oPara1.Range.Font.Bold = 1;
                oPara1.Format.SpaceAfter = 24;    //24 pt spacing after paragraph.
                oPara1.Range.InsertParagraphAfter();
            }
            #endregion 通过段落控制插入

            #region word文档设置及获取光标位置

            /// <summary>
            /// word文档设置及获取光标位置
            /// </summary>
            public static void WordSet()
            {
                object oMissing = System.Reflection.Missing.Value;
                Microsoft.Office.Interop.Word._Application WordApp;
                WordApp = new Microsoft.Office.Interop.Word.Application();

                #region 文档格式设置
                WordApp.ActiveDocument.PageSetup.LineNumbering.Active = 0;//行编号
                WordApp.ActiveDocument.PageSetup.Orientation = Microsoft.Office.Interop.Word.WdOrientation.wdOrientPortrait;//页面方向
                WordApp.ActiveDocument.PageSetup.TopMargin = WordApp.CentimetersToPoints(float.Parse("2.54"));//上页边距
                WordApp.ActiveDocument.PageSetup.BottomMargin = WordApp.CentimetersToPoints(float.Parse("2.54"));//下页边距
                WordApp.ActiveDocument.PageSetup.LeftMargin = WordApp.CentimetersToPoints(float.Parse("3.17"));//左页边距
                WordApp.ActiveDocument.PageSetup.RightMargin = WordApp.CentimetersToPoints(float.Parse("3.17"));//右页边距
                WordApp.ActiveDocument.PageSetup.Gutter = WordApp.CentimetersToPoints(float.Parse("0"));//装订线位置
                WordApp.ActiveDocument.PageSetup.HeaderDistance = WordApp.CentimetersToPoints(float.Parse("1.5"));//页眉
                WordApp.ActiveDocument.PageSetup.FooterDistance = WordApp.CentimetersToPoints(float.Parse("1.75"));//页脚
                WordApp.ActiveDocument.PageSetup.PageWidth = WordApp.CentimetersToPoints(float.Parse("21"));//纸张宽度
                WordApp.ActiveDocument.PageSetup.PageHeight = WordApp.CentimetersToPoints(float.Parse("29.7"));//纸张高度
                WordApp.ActiveDocument.PageSetup.FirstPageTray = Microsoft.Office.Interop.Word.WdPaperTray.wdPrinterDefaultBin;//纸张来源
                WordApp.ActiveDocument.PageSetup.OtherPagesTray = Microsoft.Office.Interop.Word.WdPaperTray.wdPrinterDefaultBin;//纸张来源
                WordApp.ActiveDocument.PageSetup.SectionStart = Microsoft.Office.Interop.Word.WdSectionStart.wdSectionNewPage;//节的起始位置:新建页
                WordApp.ActiveDocument.PageSetup.OddAndEvenPagesHeaderFooter = 0;//页眉页脚-奇偶页不同
                WordApp.ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = 0;//页眉页脚-首页不同
                WordApp.ActiveDocument.PageSetup.VerticalAlignment = Microsoft.Office.Interop.Word.WdVerticalAlignment.wdAlignVerticalTop;//页面垂直对齐方式
                WordApp.ActiveDocument.PageSetup.SuppressEndnotes = 0;//不隐藏尾注
                WordApp.ActiveDocument.PageSetup.MirrorMargins = 0;//不设置首页的内外边距
                WordApp.ActiveDocument.PageSetup.TwoPagesOnOne = false;//不双面打印
                WordApp.ActiveDocument.PageSetup.BookFoldPrinting = false;//不设置手动双面正面打印
                WordApp.ActiveDocument.PageSetup.BookFoldRevPrinting = false;//不设置手动双面背面打印
                WordApp.ActiveDocument.PageSetup.BookFoldPrintingSheets = 1;//打印默认份数
                WordApp.ActiveDocument.PageSetup.GutterPos = Microsoft.Office.Interop.Word.WdGutterStyle.wdGutterPosLeft;//装订线位于左侧
                WordApp.ActiveDocument.PageSetup.LinesPage = 40;//默认页行数量
                WordApp.ActiveDocument.PageSetup.LayoutMode = Microsoft.Office.Interop.Word.WdLayoutMode.wdLayoutModeLineGrid;//版式模式为“只指定行网格”
                #endregion 文档格式设置

                #region 段落格式设定
                WordApp.Selection.ParagraphFormat.LeftIndent = WordApp.CentimetersToPoints(float.Parse("0"));//左缩进
                WordApp.Selection.ParagraphFormat.RightIndent = WordApp.CentimetersToPoints(float.Parse("0"));//右缩进
                WordApp.Selection.ParagraphFormat.SpaceBefore = float.Parse("0");//段前间距
                WordApp.Selection.ParagraphFormat.SpaceBeforeAuto = 0;//
                WordApp.Selection.ParagraphFormat.SpaceAfter = float.Parse("0");//段后间距
                WordApp.Selection.ParagraphFormat.SpaceAfterAuto = 0;//
                WordApp.Selection.ParagraphFormat.LineSpacingRule = Microsoft.Office.Interop.Word.WdLineSpacing.wdLineSpaceSingle;//单倍行距
                WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphJustify;//段落2端对齐
                WordApp.Selection.ParagraphFormat.WidowControl = 0;//孤行控制
                WordApp.Selection.ParagraphFormat.KeepWithNext = 0;//与下段同页
                WordApp.Selection.ParagraphFormat.KeepTogether = 0;//段中不分页
                WordApp.Selection.ParagraphFormat.PageBreakBefore = 0;//段前分页
                WordApp.Selection.ParagraphFormat.NoLineNumber = 0;//取消行号
                WordApp.Selection.ParagraphFormat.Hyphenation = 1;//取消段字
                WordApp.Selection.ParagraphFormat.FirstLineIndent = WordApp.CentimetersToPoints(float.Parse("0"));//首行缩进
                WordApp.Selection.ParagraphFormat.OutlineLevel = Microsoft.Office.Interop.Word.WdOutlineLevel.wdOutlineLevelBodyText;
                WordApp.Selection.ParagraphFormat.CharacterUnitLeftIndent = float.Parse("0");
                WordApp.Selection.ParagraphFormat.CharacterUnitRightIndent = float.Parse("0");
                WordApp.Selection.ParagraphFormat.CharacterUnitFirstLineIndent = float.Parse("0");
                WordApp.Selection.ParagraphFormat.LineUnitBefore = float.Parse("0");
                WordApp.Selection.ParagraphFormat.LineUnitAfter = float.Parse("0");
                WordApp.Selection.ParagraphFormat.AutoAdjustRightIndent = 1;
                WordApp.Selection.ParagraphFormat.DisableLineHeightGrid = 0;
                WordApp.Selection.ParagraphFormat.FarEastLineBreakControl = 1;
                WordApp.Selection.ParagraphFormat.WordWrap = 1;
                WordApp.Selection.ParagraphFormat.HangingPunctuation = 1;
                WordApp.Selection.ParagraphFormat.HalfWidthPunctuationOnTopOfLine = 0;
                WordApp.Selection.ParagraphFormat.AddSpaceBetweenFarEastAndAlpha = 1;
                WordApp.Selection.ParagraphFormat.AddSpaceBetweenFarEastAndDigit = 1;
                WordApp.Selection.ParagraphFormat.BaseLineAlignment = Microsoft.Office.Interop.Word.WdBaselineAlignment.wdBaselineAlignAuto;
                #endregion 段落格式设定

                #region 字体格式设定
                WordApp.Selection.Font.NameFarEast = "华文中宋";
                WordApp.Selection.Font.NameAscii = "Times New Roman";
                WordApp.Selection.Font.NameOther = "Times New Roman";
                WordApp.Selection.Font.Name = "宋体";
                WordApp.Selection.Font.Size = float.Parse("14");
                WordApp.Selection.Font.Bold = 0;
                WordApp.Selection.Font.Italic = 0;
                WordApp.Selection.Font.Underline = Microsoft.Office.Interop.Word.WdUnderline.wdUnderlineNone;
                WordApp.Selection.Font.UnderlineColor = Microsoft.Office.Interop.Word.WdColor.wdColorAutomatic;
                WordApp.Selection.Font.StrikeThrough = 0;//删除线
                WordApp.Selection.Font.DoubleStrikeThrough = 0;//双删除线
                WordApp.Selection.Font.Outline = 0;//空心
                WordApp.Selection.Font.Emboss = 0;//阳文
                WordApp.Selection.Font.Shadow = 0;//阴影
                WordApp.Selection.Font.Hidden = 0;//隐藏文字
                WordApp.Selection.Font.SmallCaps = 0;//小型大写字母
                WordApp.Selection.Font.AllCaps = 0;//全部大写字母
                WordApp.Selection.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorAutomatic;
                WordApp.Selection.Font.Engrave = 0;//阴文
                WordApp.Selection.Font.Superscript = 0;//上标
                WordApp.Selection.Font.Subscript = 0;//下标
                WordApp.Selection.Font.Spacing = float.Parse("0");//字符间距
                WordApp.Selection.Font.Scaling = 100;//字符缩放
                WordApp.Selection.Font.Position = 0;//位置
                WordApp.Selection.Font.Kerning = float.Parse("1");//字体间距调整
                WordApp.Selection.Font.Animation = Microsoft.Office.Interop.Word.WdAnimation.wdAnimationNone;//文字效果
                WordApp.Selection.Font.DisableCharacterSpaceGrid = false;
                WordApp.Selection.Font.EmphasisMark = Microsoft.Office.Interop.Word.WdEmphasisMark.wdEmphasisMarkNone;
                #endregion 字体格式设定

                #region 获取光标位置
                ////get_Information
                WordApp.Selection.get_Information(WdInformation.wdActiveEndPageNumber);
                //关于行号-页号-列号-位置
                //information 属性
                //返回有关指定的所选内容或区域的信息。variant 类型,只读。
                //expression.information(type)
                //expression 必需。该表达式返回一个 range 或 selection 对象。
                //type long 类型,必需。需要返回的信息。可取下列 wdinformation 常量之一:
                //wdactiveendadjustedpagenumber 返回页码,在该页中包含指定的所选内容或区域的活动结尾。如果设置了一个起始页码,并对页码进行了手工调整,则返回调整过的页码。
                //wdactiveendpagenumber 返回页码,在该页中包含指定的所选内容或区域的活动结尾,页码从文档的开头开始计算而不考虑对页码的任何手工调整。
                //wdactiveendsectionnumber 返回节号,在该节中包含了指定的所选内容或区域的活动结尾。
                //wdatendofrowmarker 如果指定的所选内容或区域位于表格的行结尾标记处,则本参数返回 true。
                //wdcapslock 如果大写字母锁定模式有效,则本参数返回 true。
                //wdendofrangecolumnnumber 返回表格列号,在该表格列中包含了指定的所选内容或区域的活动结尾。
                //wdendofrangerownumber 返回表格行号,在该表格行包含了指定的所选内容或区域的活动结尾。
                //wdfirstcharactercolumnnumber 返回指定的所选内容或区域中第一个字符的位置。如果所选内容或区域是折叠的,则返回所选内容或区域右侧紧接着的字符编号。
                //wdfirstcharacterlinenumber 返回所选内容中第一个字符的行号。如果 pagination 属性为 false,或 draft 属性为 true,则返回 - 1。
                //wdframeisselected 如果所选内容或区域是一个完整的图文框文本框,则本参数返回 true。
                //wdheaderfootertype 返回一个值,该值表明包含了指定的所选内容或区域的页眉或页脚的类型,如下表所示。 值 页眉或页脚的类型
                //- 1 无
                //0 偶数页页眉
                //1 奇数页页眉
                //2 偶数页页脚
                //3 奇数页页脚
                //4 第一个页眉
                //5 第一个页脚
                //wdhorizontalpositionrelativetopage 返回指定的所选内容或区域的水平位置。该位置是所选内容或区域的左边与页面的左边之间的距离,以磅为单位。如果所选内容或区域不可见,则返回 - 1。
                //wdhorizontalpositionrelativetotextboundary 返回指定的所选内容或区域相对于周围最近的正文边界的左边的水平位置,以磅为单位。如果所选内容或区域没有显示在当前屏幕,则本参数返回 - 1。
                //wdinclipboard 有关此常量的详细内容,请参阅 microsoft office 98 macintosh 版的语言参考帮助。
                //wdincommentpane 如果指定的所选内容或区域位于批注窗格,则返回 true。
                //wdinendnote 如果指定的所选内容或区域位于页面视图的尾注区内,或者位于普通视图的尾注窗格中,则本参数返回 true。
                //wdinfootnote 如果指定的所选内容或区域位于页面视图的脚注区内,或者位于普通视图的脚注窗格中,则本参数返回 true。
                //wdinfootnoteendnotepane 如果指定的所选内容或区域位于页面视图的脚注或尾注区内,或者位于普通视图的脚注或尾注窗格中,则本参数返回 true。详细内容,请参阅前面的 wdinfootnote 和 wdinendnote 的说明。
                //wdinheaderfooter 如果指定的所选内容或区域位于页眉或页脚窗格中,或者位于页面视图的页眉或页脚中,则本参数返回 true。
                //wdinmasterdocument 如果指定的所选内容或区域位于主控文档中,则本参数返回 true。
                //wdinwordmail 返回一个值,该值表明了所选内容或区域的的位置,如下表所示。值 位置
                //0 所选内容或区域不在一条电子邮件消息中。
                //1 所选内容或区域位于正在发送的电子邮件中。
                //2 所选内容或区域位于正在阅读的电子邮件中。
                //wdmaximumnumberofcolumns 返回所选内容或区域中任何行的最大表格列数。
                //wdmaximumnumberofrows 返回指定的所选内容或区域中表格的最大行数。
                //wdnumberofpagesindocument 返回与所选内容或区域相关联的文档的页数。
                //wdnumlock 如果 num lock 有效,则本参数返回 true。
                //wdovertype 如果改写模式有效,则本参数返回 true。可用 overtype 属性改变改写模式的状态。
                //wdreferenceoftype 返回一个值,该值表明所选内容相对于脚注、尾注或批注引用的位置,如下表所示。 值 描述
                //— 1 所选内容或区域包含、但不只限定于脚注、尾注或批注引用中。
                //0 所选内容或区域不在脚注、尾注或批注引用之前。
                //1 所选内容或区域位于脚注引用之前。
                //2 所选内容或区域位于尾注引用之前。
                //3 所选内容或区域位于批注引用之前。
                //wdrevisionmarking 如果修订功能处于活动状态,则本参数返回 true。
                //wdselectionmode 返回一个值,该值表明当前的选定模式,如下表所示。 值 选定模式
                //0 常规选定
                //1 扩展选定
                //2 列选定
                //wdstartofrangecolumnnumber 返回所选内容或区域的起点所在的表格的列号。
                //wdstartofrangerownumber 返回所选内容或区域的起点所在的表格的行号。
                //wdverticalpositionrelativetopage 返回所选内容或区域的垂直位置,即所选内容的上边与页面的上边之间的距离,以磅为单位。如果所选内容或区域没有显示在屏幕上,则本参数返回 - 1。
                //wdverticalpositionrelativetotextboundary 返回所选内容或区域相对于周围最近的正文边界的上边的垂直位置,以磅为单位。如果所选内容或区域没有显示在屏幕上,则本参数返回 - 1。
                //wdwithintable 如果所选内容位于一个表格中,则本参数返回 true。
                //wdzoompercentage 返回由 percentage 属性设置的当前的放大百分比。
                #endregion 获取光标位置

                #region 光标移动
                //移动光标
                //光标下移3行 上移3行
                object unit = Microsoft.Office.Interop.Word.WdUnits.wdLine;
                object count = 3;
                WordApp.Selection.MoveEnd(ref unit, ref count);
                WordApp.Selection.MoveUp(ref unit, ref count, ref oMissing);

                //Microsoft.Office.Interop.Word.WdUnits说明
                //wdCell                  A cell.
                //wdCharacter             A character.
                //wdCharacterFormatting   Character formatting.
                //wdColumn                A column.
                //wdItem                  The selected item.
                //wdLine                  A line. //行
                //wdParagraph             A paragraph.
                //wdParagraphFormatting   Paragraph formatting.
                //wdRow                   A row.
                //wdScreen                The screen dimensions.
                //wdSection               A section.
                //wdSentence              A sentence.
                //wdStory                 A story.
                //wdTable                 A table.
                //wdWindow                A window.
                //wdWord                  A word.

                //录制的vb宏
                //     ,移动光标至当前行首
                //    Selection.HomeKey unit:=wdLine
                //    '移动光标至当前行尾
                //    Selection.EndKey unit:=wdLine
                //    '选择从光标至当前行首的内容
                //    Selection.HomeKey unit:=wdLine, Extend:=wdExtend
                //    '选择从光标至当前行尾的内容
                //    Selection.EndKey unit:=wdLine, Extend:=wdExtend
                //    '选择当前行
                //    Selection.HomeKey unit:=wdLine
                //    Selection.EndKey unit:=wdLine, Extend:=wdExtend
                //    '移动光标至文档开始
                //    Selection.HomeKey unit:=wdStory
                //    '移动光标至文档结尾
                //    Selection.EndKey unit:=wdStory
                //    '选择从光标至文档开始的内容
                //    Selection.HomeKey unit:=wdStory, Extend:=wdExtend
                //    '选择从光标至文档结尾的内容
                //    Selection.EndKey unit:=wdStory, Extend:=wdExtend
                //    '选择文档全部内容(从WholeStory可猜出Story应是当前文档的意思)
                //    Selection.WholeStory
                //    '移动光标至当前段落的开始
                //    Selection.MoveUp unit:=wdParagraph
                //    '移动光标至当前段落的结尾
                //    Selection.MoveDown unit:=wdParagraph
                //    '选择从光标至当前段落开始的内容
                //    Selection.MoveUp unit:=wdParagraph, Extend:=wdExtend
                //    '选择从光标至当前段落结尾的内容
                //    Selection.MoveDown unit:=wdParagraph, Extend:=wdExtend
                //    '选择光标所在段落的内容
                //    Selection.MoveUp unit:=wdParagraph
                //    Selection.MoveDown unit:=wdParagraph, Extend:=wdExtend
                //    '显示选择区的开始与结束的位置,注意:文档第1个字符的位置是0
                //    MsgBox ("第" & Selection.Start & "个字符至第" & Selection.End & "个字符")
                //    '删除当前行
                //    Selection.HomeKey unit:=wdLine
                //    Selection.EndKey unit:=wdLine, Extend:=wdExtend
                //    Selection.Delete
                //    '删除当前段落
                //    Selection.MoveUp unit:=wdParagraph
                //    Selection.MoveDown unit:=wdParagraph, Extend:=wdExtend
                //    Selection.Delete


                //表格的光标移动
                //光标到当前光标所在表格的地单元格
                WordApp.Selection.Tables[1].Cell(1, 1).Select();
                //unit对象定义
                object unith = Microsoft.Office.Interop.Word.WdUnits.wdRow;//表格行方式
                object extend = Microsoft.Office.Interop.Word.WdMovementType.wdExtend;//extend对光标移动区域进行扩展选择
                object unitu = Microsoft.Office.Interop.Word.WdUnits.wdLine;//文档行方式,可以看成表格一行.不过和wdRow有区别
                object unitp = Microsoft.Office.Interop.Word.WdUnits.wdParagraph;//段落方式,对于表格可以选择到表格行后的换车符,对于跨行合并的行选择,我能找到的最简单方式
                //object count = 1;//光标移动量

                #endregion 光标移动
            }
            #endregion word文档设置及获取光标位置

            #region 读取Word表格中某个单元格的数据。其中的参数分别为文件名(包括路径),行号,列号。

            /// <summary>
            /// 读取Word表格中某个单元格的数据。其中的参数分别为文件名(包括路径),行号,列号。
            /// </summary>
            /// <param name="fileName">word文档</param>
            /// <param name="rowIndex">行</param>
            /// <param name="colIndex">列</param>
            /// <returns>返回数据</returns>
            public static string ReadWord_tableContentByCell(string fileName, int rowIndex, int colIndex)
            {
                Microsoft.Office.Interop.Word._Application cls = null;
                Microsoft.Office.Interop.Word._Document doc = null;
                Microsoft.Office.Interop.Word.Table table = null;
                object missing = System.Reflection.Missing.Value;
                object path = fileName;
                cls = new Application();
                try
                {
                    doc = cls.Documents.Open
                      (ref path, ref missing, ref missing, ref missing,
                      ref missing, ref missing, ref missing, ref missing,
                      ref missing, ref missing, ref missing, ref missing,
                      ref missing, ref missing, ref missing, ref missing);
                    table = doc.Tables[1];
                    string text = table.Cell(rowIndex, colIndex).Range.Text.ToString();
                    text = text.Substring(0, text.Length - 2);  //去除尾部的mark
                    return text;
                }
                catch (Exception ex)
                {
                    return ex.Message;
                }
                finally
                {
                    if (doc != null)
                        doc.Close(ref missing, ref missing, ref missing);
                    cls.Quit(ref missing, ref missing, ref missing);
                }
            }
            #endregion 读取Word表格中某个单元格的数据。
            
            #region 修改word表格中指定单元格的数据
            /// <summary>
            /// 修改word表格中指定单元格的数据
            /// </summary>
            /// <param name="fileName">word文档包括路径</param>
            /// <param name="rowIndex">行</param>
            /// <param name="colIndex">列</param>
            /// <param name="content"></param>
            /// <returns></returns>
            public static bool UpdateWordTableByCell(string fileName, int rowIndex, int colIndex, string content)
            {
                Microsoft.Office.Interop.Word._Application cls = null;
                Microsoft.Office.Interop.Word._Document doc = null;
                Microsoft.Office.Interop.Word.Table table = null;
                object missing = System.Reflection.Missing.Value;
                object path = fileName;
                cls = new Application();
                try
                {
                    doc = cls.Documents.Open
                        (ref path, ref missing, ref missing, ref missing,
                      ref missing, ref missing, ref missing, ref missing,
                      ref missing, ref missing, ref missing, ref missing,
                      ref missing, ref missing, ref missing, ref missing);

                    table = doc.Tables[1];
                    //doc.Range( ref 0, ref 0 ).InsertParagraphAfter();//插入回车
                    table.Cell(rowIndex, colIndex).Range.InsertParagraphAfter();//.Text = content;
                    return true;
                }
                catch
                {
                    return false;
                }
                finally
                {
                    if (doc != null)
                    {
                        doc.Close(ref missing, ref missing, ref missing);
                        cls.Quit(ref missing, ref missing, ref missing);
                    }
                }
            }
            #endregion

            #region 关闭word进程
            /// <summary>
            /// 关闭word进程
            /// </summary>
            public static void KillWordProcess()
            {
                System.Diagnostics.Process[] myProcess;
                myProcess = System.Diagnostics.Process.GetProcesses();
                foreach (System.Diagnostics.Process process in myProcess)
                {
                    if (process.Id != 0)
                    {
                        string myS = "WINWORD.EXE" + process.ProcessName + "  ID:" + process.Id.ToString();
                        try
                        {
                            if (process.Modules != null)
                                if (process.Modules.Count > 0)
                                {
                                    System.Diagnostics.ProcessModule pm = process.Modules[0];
                                    myS += "\n Modules[0].FileName:" + pm.FileName;
                                    myS += "\n Modules[0].ModuleName:" + pm.ModuleName;
                                    myS += "\n Modules[0].FileVersionInfo:\n" + pm.FileVersionInfo.ToString();
                                    if (pm.ModuleName.ToLower() == "winword.exe")
                                        process.Kill();
                                }
                        }
                        catch
                        { }
                        finally
                        {
                        }
                    }
                }
            }
            #endregion 关闭word进程

            #region 判断系统是否装word

            /// <summary>
            /// 判断系统是否装word
            /// </summary>
            /// <returns></returns>
            public static bool IsWordInstalled()
            {
                RegistryKey machineKey = Registry.LocalMachine;
                if (IsWordInstalledByVersion("12.0", machineKey))
                {
                    return true;
                }
                if (IsWordInstalledByVersion("11.0", machineKey))
                {
                    return true;
                }
                return false;
            }


            /// <summary>
            /// 判断系统是否装某版本的word
            /// </summary>
            /// <param name="strVersion">版本号</param>
            /// <param name="machineKey"></param>
            /// <returns></returns>
            private static bool IsWordInstalledByVersion(string strVersion, RegistryKey machineKey)
            {
                try
                {
                    RegistryKey installKey =
                        machineKey.OpenSubKey("Software").OpenSubKey("Microsoft").OpenSubKey(
                        "Office").OpenSubKey(strVersion).OpenSubKey("Word").OpenSubKey("InstallRoot");
                    if (installKey == null)
                    {
                        return false;
                    }
                    return true;
                }
                catch(Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);
                    return false;
                }
            }
            #endregion 判断系统是否装word
        }
    }
    posted @ 2012-05-18 23:23  ChaunceyHao  阅读(190)  评论(0编辑  收藏  举报
  • 汽车羊毛坐垫长毛
  • 车垫四季通用
  • 御车宝
  • 凯美瑞坐垫四季通用
  • 手编冰丝坐垫
  • 珍珠戒指新款
  • 汽车皮坐垫四季垫
  • 汽车四季坐垫新款
  • 汽车皮坐垫四季通用
  • 汽车羊毛坐垫短毛
  • 包女
  • 汽车亚麻坐垫包邮
  • 汽车布坐垫
  • 汽车布坐垫套
  • 紫风铃亚麻四季坐垫
  • 蒙奇奇汽车
  • 蒙奇奇汽车毛绒坐垫
  • 蒙奇奇坐垫三件套
  • 尼罗河车坐垫
  • 尼罗河手编坐垫
  • 尼罗河四季垫
  • 羊剪绒坐垫
  • 牧宝冬季坐垫
  • 牧宝四季垫正品
  • 牧宝羽绒坐垫
  • 牧宝汽车垫羊毛
  • 高压洗车机
  • 高压洗车器
  • 高压洗车水泵
  • 高压洗车泵
  • 熊猫洗车
  • 洗车器高压220v
  • 洗车器便携高压
  • 高压水枪洗车机
  • 220v高压水枪洗车机
  • 家用洗车水枪高压枪
  • 汽车洗车水枪
  • 虎贝尔洗车水枪
  • 水枪头洗车
  • 洗车水枪水管
  • 洗车水枪套装
  • 洗车水枪接头
  • 佳百丽洗车水枪
  • 洗车工具套装
  • 洗车用品工具
  • 家用洗车工具
  • 汽车洗车工具
  • 洗车设备工具
  • 洗车刷子
  • 现代途胜保险杠
  • 现代新胜达保险杠
  • 保险杠车贴纸
  • 后保险杠车贴纸
  • 前保险杠车贴
  • 雨燕保险杠
  • 后保险杠贴纸
  • 前保险杠贴纸
  • 汽车保险贴纸
  • rav4后保险杠
  • 专业运动文胸htc c715e evo design 4g
  • htc evo 4g a9292
  • htc x515m g17 evo 3d
  • htc one x s720e
  • htc x920e
  • 名牌手表男正品
  • povos 奔腾 pffn3003苏泊尔电热水壶正品
  • tcl tcl电热水壶ta-kb181a
  • 乔邦181j
  • 乔邦不锈钢电热水壶
  • supor 苏泊尔 swf15j3-150
  • 逸动空气滤芯
  • 空气压缩机喷漆
  • 德国车载空气净化器
  • sr927w手表电池
  • cartier手表蓝气球
  • 机械手表男士名表
  • anne klein手表
  • 手表柜台展示柜
  • 女士皮带 头层牛皮
  • 女士皮带 头层纯牛皮
  • jeep皮带 纯牛皮
  • 女皮带 真皮 牛皮
  • 女士皮带 真皮
  • 头层牛皮皮带
  • 女士皮带 时尚
  • 真皮皮带头层牛皮女
  • 女士皮带 包邮
  • 皮带条 头层牛皮
  • 女士皮带 时尚 宽
  • 头层牛皮纯铜扣皮带
  • 女士皮带 纯牛皮
  • 女士皮带头层纯牛皮
  • 女士皮带头层牛皮
  • jeep皮带纯牛皮
  • 女皮带真皮牛皮
  • 女士皮带真皮
  • 女士牛皮皮带包邮
  • 女士皮带时尚
  • 三星微单镜头
  • 三星单反镜头
  • 三星50-200镜头
  • 三星7100镜头保护膜
  • 三星i9210
  • 三星i9210手机套面包蛋糕酸奶机
  • 鸡蛋牛奶面包干饼干
  • 面包片饼干
  • 摩托车机油