Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5487
  • 博文数量: 5
  • 博客积分: 328
  • 博客等级: 一等列兵
  • 技术积分: 150
  • 用 户 组: 普通用户
  • 注册时间: 2012-11-04 09:53
文章分类
文章存档

2012年(5)

我的朋友
最近访客

分类: 嵌入式

2012-11-04 10:05:07

前提:引入COM组件
1、创建
object oMissing = System.Reflection.Missing.Value;
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
2、打开
object oMissing = System.Reflection.Missing.Value;
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
object fileName = @"E:CCCXCXXTestDoc.doc";
oDoc = oWord.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);
3、导入模板
object oMissing = System.Reflection.Missing.Value;
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
object fileName = @"E:XXXCCXTest.doc";
oDoc = oWord.Documents.Add(ref fileName, ref oMissing, ref oMissing, ref oMissing);
4、添加新表
object oMissing = System.Reflection.Missing.Value;
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
object fileName = @"E:XXXCCXTest.doc";
oDoc = oWord.Documents.Add(ref fileName, ref oMissing, ref oMissing, ref oMissing);
5、表插入行
object oMissing = System.Reflection.Missing.Value;
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
object start = 0;
object end = 0;
Word.Range tableLocation = oDoc.Range(ref start, ref end);
oDoc.Tables.Add(tableLocation, 3, 4, ref oMissing, ref oMissing);
Word.Table newTable = oDoc.Tables[1];
object beforeRow = newTable.Rows[1];
newTable.Rows.Add(ref beforeRow);
6、单元格合并
object oMissing = System.Reflection.Missing.Value;
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
object start = 0;
object end = 0;
Word.Range tableLocation = oDoc.Range(ref start, ref end);
oDoc.Tables.Add(tableLocation, 3, 4, ref oMissing, ref oMissing);
Word.Table newTable = oDoc.Tables[1];
object beforeRow = newTable.Rows[1];
newTable.Rows.Add(ref beforeRow);
Word.Cell cell = newTable.Cell(1, 1);
cell.Merge(newTable.Cell(1, 2));
7、单元格分离
object oMissing = System.Reflection.Missing.Value;
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
oDoc = oWord.Documents.Add(oMissing, ref oMissing, ref oMissing);
object start = 0;
object end = 0;
Word.Range tableLocation = oDoc.Range(ref start, ref end);
oDoc.Tables.Add(tableLocation, 3, 4, ref oMissing, ref oMissing);
Word.Table newTable = oDoc.Tables[1];
object beforeRow = newTable.Rows[1];
newTable.Rows.Add(ref beforeRow);
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);
8、通过段落控制插入
object oMissing = System.Reflection.Missing.Value;
object oEndOfDoc = @"\endofdoc";
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
Word.Paragraph oPara1;
oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing);
oPara1.Range.Text = "Heading 1";
oPara1.Range.Font.Bold = 1;
oPara1.Format.SpaceAfter = 24;oPara1.Range.InsertParagraphAfter();
公司发布
阅读(293) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:类库或程序强签名

给主人留下些什么吧!~~