-1

这适用于 Visual Studio 的服务器,但是当服务器更改为 IIS 时,它会抛出:

由于以下错误,从 IClassFactory 创建 CLSID 为 {00020906-0000-0000-C000-000000000046} 的 COM 组件实例失败:8001010a。

        object initial_limits = 0;
        object missing = System.Reflection.Missing.Value;
        object Visible = true;
        object openfilename = @"C:\letters\Templates\" + template_src_dropdown.SelectedValue + ".doc";
        current_date = DateTime.Now.Date.ToString("dd/MM/yyyy");

        object savefilename = @"C:\letters\Letters\" + reference_id + ".doc";


        ApplicationClass WordApp = new ApplicationClass();
        Document WordDoc = new Document();
        Document docActive = null;
        WordDoc = WordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);


        //Document 



        //WordDoc = WordApp.Documents.Open(ref openfilename, 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);          

        /*
        if (new_file_chkbox.Checked == true)
        {

            WordDoc = WordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);
        }
        else
        {
            WordDoc = WordApp.Documents.Open(ref openfilename, 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);
        }
        */


        try
        {


            docActive = WordApp.ActiveDocument;
            Bookmark bookmark1;
            bookmark1 = docActive.Bookmarks.Add("word_content", ref missing);
            Range rng_bookmark1 = bookmark1.Range;

            rng_bookmark1.Text = reference_id + "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + current_date;
            rng_bookmark1.Text += employee_list_word + vendor_list_word;
            rng_bookmark1.Text += "\n" + subject_txtbox.Text + "\n\n";
            rng_bookmark1.Text += "\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + designation_dropdown.SelectedValue + "\n";
            rng_bookmark1.Text += "\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + department_dropdown.SelectedValue + "\n";
            rng_bookmark1.Text += cc_employee_list_word + cc_vendor_list_word;



            try
            {
                WordDoc.SaveAs(ref savefilename, 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);
                WordApp.Visible = true;
            }

            catch (Exception ex)
            {
                Label1.Text = ex.Message;
                //MessageBox.Show(ex.Message);
            }

            finally 
            {
                WordApp.Quit(ref missing, ref missing, ref missing);
             }
4

1 回答 1

1

VS 服务器是开发服务器,IIS 是部署服务器。这很容易理解,在 Web 应用程序中您无法获得桌面应用程序的功能,因为如果发生这种情况,那么没有人会获得 MS Word 的许可版本。它将成为多用户然后...
更好地使用 OpenXml ...代码 project.com 中提供了 openXml 的良好示例

于 2011-09-26T09:55:15.813 回答