- OperateWord ow = new OperateWord();
- Microsoft.Office.Interop.Word.ApplicationClass ss = ow.WordApplication;
- AddContent(ref ss);
-
- void AddContent(ref Microsoft.Office.Interop.Word.ApplicationClass app)
- {
-
- Object oMissing = System.Reflection.Missing.Value;
- Object oTrue = true;
- Object oFalse = false;
- Object oUpperHeadingLevel = "1";
- Object oLowerHeadingLevel = "3";
- Object oTOCTableID = "TableOfContents";
-
- app.Selection.Start = 0;
-
- app.Selection.End = 0;
-
- object beginLevel = 2;
-
- object endLevel = 2;
-
- object rightAlignPageNumber = true;
-
-
- app.Application.ActiveDocument.TablesOfContents.Add(app.Selection.Range, ref oTrue, ref oUpperHeadingLevel,
- ref oLowerHeadingLevel, ref oMissing, ref oTOCTableID, ref oTrue,
- ref oTrue, ref oMissing, ref oTrue, ref oTrue, ref oTrue);
-
-
- }
参考1:
- private void button1_Click(object sender, EventArgs e)
- {
- Object oMissing = System.Reflection.Missing.Value;
- Object oTrue = true;
- Object oFalse = false;
-
- Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
- Microsoft.Office.Interop.Word.Document doc = new Microsoft.Office.Interop.Word.Document();
-
- oWord.Visible = true;
- object fileName = this.textBox1.Text;
- doc = 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);
-
-
- oWord.Selection.Paragraphs.OutlineLevel = WdOutlineLevel.wdOutlineLevel2;
- oWord.Selection.Paragraphs.OutlineLevel = WdOutlineLevel.wdOutlineLevel3;
- oWord.Selection.Paragraphs.OutlineLevel = WdOutlineLevel.wdOutlineLevelBodyText;
-
- object x = 0;
- Range myRange = doc.Range(ref x, ref x);
- Object oUpperHeadingLevel = "1";
- Object oLowerHeadingLevel = "3";
- Object oTOCTableID = "TableOfContents";
- doc.TablesOfContents.Add(myRange, ref oTrue, ref oUpperHeadingLevel,
- ref oLowerHeadingLevel, ref oMissing, ref oTOCTableID, ref oTrue,
- ref oTrue, ref oMissing, ref oTrue, ref oTrue, ref oTrue);
-
-
-
-
-
-
- }
-
- private void button2_Click(object sender, EventArgs e)
- {
- OpenFileDialog fd = new OpenFileDialog();
- if (fd.ShowDialog() == DialogResult.OK)
- {
- this.textBox1.Text = fd.FileName;
- }
- }
参考2:
- void AddContent(ref Word.Appliction app)
-
- {
-
- app.Selection.Start=0;
-
- app.Selection.End=0;
-
- object beginLevel=2;
-
- object endLevel=2;
-
- object rightAlignPageNumber=true;
-
- app.ActiveDocument.TablesOfContents.Add(app.Selection.Range,ref miss,rightAlignPageNumber,ref miss,
-
- ref miss,ref miss,ref miss,ref miss);
C#操作Word生成目录,布布扣,bubuko.com
C#操作Word生成目录
原文:http://www.cnblogs.com/gc2013/p/3824593.html