C#操作WORD(二)
来源:互联网 发布:d3.js实例 编辑:程序博客网 时间:2024/09/21 06:36
上一篇讲到,一个Document可能会有多个Rang对象。Rang由起始和结束字符来定他的位置。
以下代码为先清空Document里的内容,再在第一行写入内容。
// Clear out any existing information.
Object start = Type.Missing;
Object end = Type.Missing;
Object unit = Type.Missing;
Object count = Type.Missing;
ThisDocument.Range(ref start, ref end). Delete(ref unit, ref count);
// Set up the header information.
start = 0;
end = 0;
rng = ThisDocument.Range(ref start, ref end);
rng.InsertBefore("Xiaopai");
rng.Font.Name = "Verdana";
rng.Font.Size = 16;
rng.InsertParagraphAfter();//输入回车
以下为在刚写入的内容后添加一个表格。
object missingValue = Type.Missing;
object location = 8; //注:若location超过已有字符的长度将会出错。
Word.Range rng = ThisDocument.Range(ref location, ref location);
ThisDocument.Tables.Add(rng, 3, 4, ref missingValue, ref missingValue);
以下为在刚创建的表格里添加一行
Word.Table tbl = ThisDocument.Tables[1]; //第一个表格为1,而不是0
Object beforeRow = Type.Missing;
tbl.Rows.Add(ref beforeRow); //在表格的最后添加一行
填充表格内容
tbl.Cell(1, 1).Range.Text = "shuai"; //在表格的第一行第一列填入内容。
设置单元格风格
Word.Range rngCell;
rngCell = tbl.Cell(1, 2).Range;
rngCell.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight;
rngCell.Font.Size = 8;
rngCell.Font.Name = "Verdana";
当时没找到合并单元格的方法。有谁知道的共享一下哈。
参考资料:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_wrcore/html/wrtskhowtocreatewordtables.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_wrcore/html/wrtskhowtoaddrowscolumnstowordtables.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_vsto2003_ta/html/odc_VSTWordtbl.asp
以下代码为先清空Document里的内容,再在第一行写入内容。
// Clear out any existing information.
Object start = Type.Missing;
Object end = Type.Missing;
Object unit = Type.Missing;
Object count = Type.Missing;
ThisDocument.Range(ref start, ref end). Delete(ref unit, ref count);
// Set up the header information.
start = 0;
end = 0;
rng = ThisDocument.Range(ref start, ref end);
rng.InsertBefore("Xiaopai");
rng.Font.Name = "Verdana";
rng.Font.Size = 16;
rng.InsertParagraphAfter();//输入回车
以下为在刚写入的内容后添加一个表格。
object missingValue = Type.Missing;
object location = 8; //注:若location超过已有字符的长度将会出错。
Word.Range rng = ThisDocument.Range(ref location, ref location);
ThisDocument.Tables.Add(rng, 3, 4, ref missingValue, ref missingValue);
以下为在刚创建的表格里添加一行
Word.Table tbl = ThisDocument.Tables[1]; //第一个表格为1,而不是0
Object beforeRow = Type.Missing;
tbl.Rows.Add(ref beforeRow); //在表格的最后添加一行
填充表格内容
tbl.Cell(1, 1).Range.Text = "shuai"; //在表格的第一行第一列填入内容。
设置单元格风格
Word.Range rngCell;
rngCell = tbl.Cell(1, 2).Range;
rngCell.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight;
rngCell.Font.Size = 8;
rngCell.Font.Name = "Verdana";
当时没找到合并单元格的方法。有谁知道的共享一下哈。
参考资料:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_wrcore/html/wrtskhowtocreatewordtables.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_wrcore/html/wrtskhowtoaddrowscolumnstowordtables.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_vsto2003_ta/html/odc_VSTWordtbl.asp
- C#操作WORD(二)
- c#操作word(二)
- c#操作word(二)
- C#操作word文档(二)
- C#操作word文档(二)
- c#操作word图表(二)
- C# Aspose.Word 操作word文档【二】
- C#操作word例程之二
- C#对Word的操作(二)
- C# 操作Word知识汇总 二
- C#操作Word(二)——将Word文档嵌入到WinForm窗体中
- C#操作Word(二)——将Word文档嵌入到WinForm窗体中
- C#操作WORD(一)
- C# Word操作(转载)
- Word操作三步曲(二)
- poi操作word(二)
- VS2010 操作Word(二)基本操作
- C#中操作Word(9)—— 向Word中插入图表的三种方法(二)
- Java平台I18N 支持概述
- c#读取数据库到xml文件中
- JAVA面试题集锦
- c#textBox中换行
- C#操作WORD(一)
- C#操作WORD(二)
- C#处理文本文件
- Xbox 360革命性应用:终结PC时代 开启X时代
- 11月27日,轩音乐工作室搭建成功!
- JSP+JavaBean应用JFreeChart[转]
- Java web应用开源框架串讲
- LiNKGRABBER v.3.0.4 ENGLiSH EDiTiON
- MySQL中文参考手册--MySQL教程(4)--创造并使用一个数据库
- 错误和AJAX[转]