using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Office.Interop.Word;
using System.Reflection; namespace WordAndExcel.Word
{
public partial class makeWord : System.Web.UI.Page
{
Microsoft.Office.Interop.Word.Application appWord = null;
Microsoft.Office.Interop.Word.Document docWord = null;
Range range = null;
object missing = null; protected void Page_Load(object sender, EventArgs e)
{
Document wordDoc = OpenWord(Server.MapPath("./file/law.doc"));
MakeWord(wordDoc, Server.MapPath("./file/laws.doc"));
}
/// <summary>
/// 打开Word
/// </summary>
/// <param name="str_Path">文件路径</param>
/// <returns></returns>
protected Document OpenWord(object str_Path)
{
missing = Missing.Value;
appWord = new Microsoft.Office.Interop.Word.Application();
appWord.Visible = false;
docWord = appWord.Documents.Open(ref str_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);
return docWord;
}
/// <summary>
/// 操作Word
/// </summary>
/// <param name="docWord">文档对象</param>
protected void MakeWord(Document docWord, object str_Path)
{
try
{
object startPostion = (docWord.Characters.Count - ) as object;
Range tableLocation = docWord.Range(ref startPostion, ref startPostion); ///文檔對象 從頭開始
///
Microsoft.Office.Interop.Word.Table newTable = docWord.Tables.Add(tableLocation, , , ref missing, ref missing);
///table 樣式
newTable.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleDashDotDot;
newTable.Borders.InsideLineStyle = WdLineStyle.wdLineStyleDashDotDot;
for (int i = ; i < ; i++)
{
for (int j = ; j < ; j++)
{
newTable.Rows[i + ].Cells[j + ].Width = (float)(255F);
newTable.Rows[i + ].Cells[j + ].Height = (float)(155F);
TableAddText(newTable.Rows[i + ].Cells[j + ].Range);
} }
}
catch (Exception ee)
{
Response.Write(ee.ToString());
}
finally
{ object saveChange = true;
docWord.SaveAs(ref str_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);
docWord.Close(ref saveChange, ref missing, ref missing);
appWord.Quit(ref saveChange, ref missing, ref missing);
}
} public void TableAddText(Range range)
{
range.Text = "John:(寄)";
// appWord.Selection.Text = "童新:(寄)";
// appWord.Selection.TypeParagraph();
// appWord.Selection.Text = "童新:(收)";
range.Text += "Jerry:(收)";
object Anchor = range; // 插入圖片
string FileName = Server.MapPath("./file/law.jpg");//图片所在路径
object LinkToFile = false;
object SaveWithDocument = true;
// object Anchor = docWord.Application.Selection.Range;
docWord.Application.ActiveDocument.InlineShapes.AddPicture(FileName, ref LinkToFile, ref SaveWithDocument, ref Anchor);
docWord.Application.ActiveDocument.InlineShapes[].Width = 100f;//图片宽度
docWord.Application.ActiveDocument.InlineShapes[].Height = 20f;//图片高度 //插入Hyperlink
Microsoft.Office.Interop.Word.Selection mySelection = appWord.ActiveWindow.Selection;
mySelection.Start = ;
mySelection.End = ;
Microsoft.Office.Interop.Word.Range myRange = mySelection.Range;
Microsoft.Office.Interop.Word.Hyperlinks myLinks = docWord.Hyperlinks;
object linkAddr = @"http://www.cnblogs.com/tx720/";
Microsoft.Office.Interop.Word.Hyperlink myLink = myLinks.Add(myRange, ref linkAddr,ref missing);
appWord.ActiveWindow.Selection.InsertAfter("\n"); //添加舉行形狀 并且添加文字
Shape s = range.Document.Shapes.AddShape(, , , , , ref Anchor);
s.TextFrame.TextRange.Text = "dds"; }
}
}

c# 操作word的更多相关文章

  1. python操作word入门

    1.安装pywin32 http://sourceforge.net/projects/pywin32 在files里去找适合你的python版本.截止此文,最新版本是pywin32-219快捷路径: ...

  2. C#中操作Word(1)—— word对象模型介绍

    一.开发环境布置 C#中添加对Word的支持,只需添加对Microsoft.Office.Interop.Word的命名空间,如下图所示,右键点击“引用”,在弹出的“添加引用”对话框中选中COM标签页 ...

  3. C#操作Word的超详细总结

    本文中用C#来操作Word,包括: 创建Word: 插入文字,选择文字,编辑文字的字号.粗细.颜色.下划线等: 设置段落的首行缩进.行距: 设置页面页边距和纸张大小: 设置页眉.页码: 插入图片,设置 ...

  4. C#操作word模板插入文字、图片及表格详细步骤

    c#操作word模板插入文字.图片及表格 1.建立word模板文件 person.dot用书签 标示相关字段的填充位置 2.建立web应用程序 加入Microsoft.Office.Interop.W ...

  5. C#操作Word的辅助类(word2003) 修改完善版

    转自:http://blog.csdn.net/jiutao_tang/article/details/6567608 该类在他人编写的几个类基础上扩展完善而来,主要功能有: (1)插入文本 (2)插 ...

  6. 黄聪:C#操作Word表格的常见操作(转)

    几种常见C#操作Word表格操作有哪些呢?让我们来看看具体的实例演示: bool saveChange = false; //C#操作Word表格操作 object missing = System. ...

  7. c#操作word表格

    http://www.webshu.net/jiaocheng/programme/ASPNET/200804/6499.html <% if request("infoid" ...

  8. Aspose.Words操作word生成PDF文档

    Aspose.Words操作word生成PDF文档 using Aspose.Words; using System; using System.Collections.Generic; using ...

  9. OpenXML操作word

    OpenXML概述 项目中经常需要操作word,之前的方式是采用COM接口,这个接口很不稳定,经常报错.现在开始采用OpenXML.OpenXML(OOXML)是微软在Office 2007中提出的一 ...

随机推荐

  1. RT-thread内核之进程间通信

    这里面见到的同步和互斥的概念非常清晰,转载自: http://www.cnblogs.com/King-Gentleman/p/4311582.html 一.进程间通信机制 rt-thread操作系统 ...

  2. Nuttx操作系统

    前几天答辩的时候看到有同学在用,回来后查了点资料. 来源:天又亮了 1  NuttX 实时操作系统 NuttX 是一个实时操作系统(RTOS),强调标准兼容和小型封装,具有从8位到32位微控制器环境的 ...

  3. HBase Shell手动移动Region

    在生产环境中很有可能有那么几个Region比较大,但是都运行在同一个Regionserver中. 这个时候就需要手动将region移动到负载低的Regionserver中. 步骤: 1.找到要移动的r ...

  4. Juicer javascript 模板引擎

    模板引擎是为了使用户界面与业务数据(内容)分离而产生的,它可以生成特定格式的文档,用于网站的模板引擎就会生成一个标准的HTML文档. js模板引擎包括如下:template官方参考:http://au ...

  5. redis 应用

    前段使用JQueryMobile进行展示. 实现了用户注册,登陆,列表基本功能 非常简洁. 如果想了解Redis存储,Express的处理可以提供一些基础的示范. 下载地址: https://gith ...

  6. 【转】Maven实战(三)---插件动态打包

    原博文出于:http://blog.csdn.net/liutengteng130/article/details/41622013    感谢! maven把项目的构建划分为不同的生命周期(life ...

  7. 现代程序设计——homework-10

    设计 对于MVC我的理解是这样的,V是台显示器,注意仅仅是一台比显示器普通显示器多几个按钮,用户按什么,按了什么该干什么都不用操心:M是实体的软件抽象,假设实体可以但不执行,我就可以一步一步走,实体可 ...

  8. 关于Js脚本的延迟执行

      关于标签,我们有一般会放在两个地方,一个是在标签的内部,另一个是放在前面.这一次我们着重讲解一下放在标签内部.在我们用Js操作DOM元素时,如果不延时执行,DOM元素其实是根本还没有被渲染出来的. ...

  9. thymeleaf中的内联[ [ ] ]

    一.文本内联 [[…]]之间的表达式在Thymeleaf被认为是内联表达式,在其中您可以使用任何类型的表达式,也会有效th:text属性. <p>Hello, [[${session.us ...

  10. IntelliJ IDEA 开发工具项目maven管理

    今天自己重新部署一下intellij下的项目开发环境,顺便把maven管理项目jar包的方法梳理一下 (1)首先下载apache-maven-3.0.4版本的maven,我自己解压在D:\maven\ ...