这适用于 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);
}