这适用于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);
}
答案 0 :(得分:1)
VS服务器是开发服务器,IIS是部署服务器。
这很容易理解,在Web应用程序中,您无法获得桌面应用程序的功能,因为如果发生这种情况,那么没有人会获得MS Word的许可版本。
那将是多用户然后...
更好地使用OpenXml ......
Code project.com中提供了openXml的好例子