当前位置:编程学习 > C#/ASP.NET >>

我有一段C#文档生成的程序,调试没问题但是出不来结果

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
using System.Diagnostics;

using Word = Microsoft.Office.Interop.Word;
namespace _2013_6_17文档生成
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Word.Application oWord;
        Word._Document oDoc;
        object oTemplate;
        private void button1_Click(object sender, EventArgs e)
        {
            object oMissing = System.Reflection.Missing.Value;
            oWord = new Word.Application();
            oWord.Visible = false;
            object oTemplate = "D://test_moban2.dot";          
            oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing, ref oMissing, ref oMissing);
            object[] oBookMark = new object[20];
            oBookMark[0] = "test_case_number";
            oBookMark[1] = "test_content";
            oBookMark[2] = "test_worker";
            oBookMark[3] = "test_time";
            oBookMark[4] = "train_moving_access";
            oBookMark[5] = "test_condition";
            oBookMark[7] = "Testing_allows_speed";
            oBookMark[8] = "The_station_diagram";
            //序1;步骤1
            oBookMark[9] = "number";
            oBookMark[10] = "The_station_interval";
            oBookMark[11] = "special_place";
            oBookMark[12] = "execution_mode";
            oBookMark[13] = "ground_condition";
            oBookMark[14] = "driver_operation";
            oBookMark[15] = "Case_description";
            oBookMark[16] = "After_execution_mode";
            oBookMark[17] = "Hope_results";
            oBookMark[18] = "note";
            oBookMark[19] = "sequence_num";
            
            oDoc.Bookmarks.get_Item(ref oBookMark[0]).Range.Text = "JH-CTCS3-ATP-001";
            oDoc.Bookmarks.get_Item(ref oBookMark[1]).Range.Text = "1、模式转换   2、引导接发车   3、RBC切换(双电台)";
            oDoc.Bookmarks.get_Item(ref oBookMark[2]).Range.Text = "张三";
            oDoc.Bookmarks.get_Item(ref oBookMark[3]).Range.Text = "2013-06-18";
            oDoc.Bookmarks.get_Item(ref oBookMark[4]).Range.Text = "枣庄西XIG正向发车,徐州东IG正向引导接发车,宿州东IG正向通过,蚌埠南XIIG正向接车";
            oDoc.Bookmarks.get_Item(ref oBookMark[5]).Range.Text = "双电台";
            oDoc.Bookmarks.get_Item(ref oBookMark[7]).Range.Text = "列车最高允许速度310km/h";
            oDoc.Bookmarks.get_Item(ref oBookMark[8]).Range.Text = "";
            oDoc.Bookmarks.get_Item(ref oBookMark[9]).Range.Text = "1.";
            oDoc.Bookmarks.get_Item(ref oBookMark[10]).Range.Text = "枣庄西站";
            oDoc.Bookmarks.get_Item(ref oBookMark[11]).Range.Text = "";
            oDoc.Bookmarks.get_Item(ref oBookMark[12]).Range.Text = "";
            oDoc.Bookmarks.get_Item(ref oBookMark[13]).Range.Text = "";
            oDoc.Bookmarks.get_Item(ref oBookMark[14]).Range.Text = "ATP上电,选择C3目视模式";
            oDoc.Bookmarks.get_Item(ref oBookMark[15]).Range.Text = "";
            oDoc.Bookmarks.get_Item(ref oBookMark[16]).Range.Text = "C3:OS";
            oDoc.Bookmarks.get_Item(ref oBookMark[17]).Range.Text = "ATP上电,执行自检程序,列车位置未知,列车转入C3目视模式";
            oDoc.Bookmarks.get_Item(ref oBookMark[18]).Range.Text = "";
            oDoc.Bookmarks.get_Item(ref oBookMark[19]).Range.Text = "序列1 CO下相关功能验证(下行正向)";

   

            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "Word Document(*.doc)|*.doc";
            sfd.DefaultExt = "Word Document(*.doc)|*.doc";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                object filename1 = sfd.FileName;

                oDoc.SaveAs(ref filename1, 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);
                oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
                //关闭word  
                oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            object oMissing = System.Reflection.Missing.Value;
            Word.Application oWord = new Word.Application();
            oWord.Visible = false;
            object oTemplate = "D://test_moban2.dot"; 
            oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing, ref oMissing, ref oMissing);
            Word.Table nowTable = oDoc.Tables[1];
            Word.Range last_range = oDoc.Paragraphs.Last.Range;
            int row_count =1;
            Word.Table nowtable = oDoc.Tables.Add(last_range, row_count, 10, ref oMissing, ref oMissing);
            MessageBox.Show("添加成功");
        }
    }

}
//求大神指导为什么出不来结果~各位大牛快快显灵~ C#/文档生成 --------------------编程问答-------------------- 帮顶!!!!!另外,求大神帮忙:http://bbs.csdn.net/topics/390501016 --------------------编程问答--------------------  object oTemplate;
        private void button1_Click(object sender, EventArgs e)
        {
            object oMissing = System.Reflection.Missing.Value;
            oWord = new Word.Application();
            oWord.Visible = false;
            object oTemplate = "D://test_moban2.dot";          
不要重复声明,去掉下面那个声明看看oTemplate = "D://test_moban2.dot"; 
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,