私は MS Word テンプレート ジェネレーターに取り組んでいます。次のように動作します。
ユーザーがWebページを開いていくつかのテキストボックスに入力し、いくつかのチェックボックスをマークしてからボタンをクリックすると、Word文書が開き(以前に定義した必要なすべてのブックマークを備えたテンプレート)、Webページに入力したものを使用して、すべて文書に含まれていますフィールドとチェック ボックスはマークしたとおりにマークされているため、ドキュメントを印刷するだけで済みます。それは私のPCで完全に機能しました
しかし、サーバーでテストしたところ、エラーが発生しました。
私のコード: 参照を含めました ( using Word = Microsoft.Office.Interop.Word;
)
private void CreateWordDocument(int DepositNo)
{
Random RandomClass = new Random();
int randomInt = RandomClass.Next();
string templateName = "Form15Template.docx";
string docFileName = "Form15_" + DepositNo.ToString() + "_" + randomInt.ToString() + ".docx";
string destenation = "D:\\_Documents\\Form15\\";
File.Copy(Server.MapPath(@"_Documents/" + templateName), destenation + docFileName, true); //
String POBox = "9769";
String City = "الرياض";
String PostalCode = "11423";
String Address = "ص.ب " + POBox + " " + City + " " + PostalCode;
// Modify Checkboxes variables in Doc to true if they have been checked
if (RadioButtonListResult.SelectedValue.Equals("اجتاز"))
A = true;
if (RadioButtonListResult.SelectedValue.Equals("تعديل") || RadioButtonListResult.SelectedValue.Equals("لم يجتز"))
B = true;
if (CheckBoxAllElements.Checked)
AllElements = true;
if (CheckBoxElements.Checked)
Elements = true;
if (CheckBoxEdit.Checked)
Edit = true;
if (CheckBoxBoxPage.Checked)
BoxPage = true;
if (CheckBoxRequestArabic.Checked)
RequestArabic = true;
if (CheckBoxMultiInvention.Checked)
MultiInvention = true;
if (CheckBoxRecency.Checked)
Recency = true;
if (CheckBoxInventiveStep.Checked)
InventiveStep = true;
if (CheckBoxImplemented.Checked)
Implemented = true;
if (CheckBoxC.Checked)
C = true;
if (CheckBoxD.Checked)
D = true;
object bA = "A", bB = "B", bC = "C", bD = "D", bAllElements = "AllElements", bElements = "Elements",
bRecency = "Recency", bInventiveStep = "InventiveStep", bImplemented = "Implemented",
bApprove = "Approve", bEdit = "Edit", bBoxPage = "BoxPage", bRequestArabic = "RequestArabic",
bMultiInvention = "MultiInvention", bObjection = "Objection", bMark = "Mark",
bRejection = "Rejection";
//Start Word and open template.
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
object FileName = @"C:\Users\aalhammad\Documents\Visual Studio 2010\Projects\FormEditing\FormEditing\_Documents\Form15Template.docx";
object oMissing = System.Reflection.Missing.Value;
oDoc = 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);
// ============================================== CheckBoxes ====================================================
// Modifying CheckBoxes in Document
oDoc.FormFields.get_Item(ref bA).CheckBox.Value = A;
oDoc.FormFields.get_Item(ref bB).CheckBox.Value = B;
oDoc.FormFields.get_Item(ref bC).CheckBox.Value = C;
oDoc.FormFields.get_Item(ref bD).CheckBox.Value = D;
oDoc.FormFields.get_Item(ref bAllElements).CheckBox.Value = AllElements;
oDoc.FormFields.get_Item(ref bElements).CheckBox.Value = Elements;
oDoc.FormFields.get_Item(ref bRecency).CheckBox.Value = Recency;
oDoc.FormFields.get_Item(ref bInventiveStep).CheckBox.Value = InventiveStep;
oDoc.FormFields.get_Item(ref bImplemented).CheckBox.Value = Implemented;
oDoc.FormFields.get_Item(ref bApprove).CheckBox.Value = Approve;
oDoc.FormFields.get_Item(ref bEdit).CheckBox.Value = Edit;
oDoc.FormFields.get_Item(ref bBoxPage).CheckBox.Value = BoxPage;
oDoc.FormFields.get_Item(ref bRequestArabic).CheckBox.Value = RequestArabic;
oDoc.FormFields.get_Item(ref bMultiInvention).CheckBox.Value = MultiInvention;
oDoc.FormFields.get_Item(ref bObjection).CheckBox.Value = Objection;
oDoc.FormFields.get_Item(ref bMark).CheckBox.Value = Mark;
oDoc.FormFields.get_Item(ref bRejection).CheckBox.Value = Rejection;
// ============================================== BookMarks =====================================================
String ApplicantName = "شركة الزيت العربية السعودية",
AgentName = "مكتب سليمان العمار للمحاماة والاستشارات القانونية",
AppDate = "13/01/2013",
Title = "حماية خط تدفق رأس بئر ونظام اختبار باستخدام وحدة تحكم في سرعة مضخة كهربائية مغمورة وصمام فاصل يستخدم عند الطوارئ";
// find bookmark
object oBookmark = "DepositNO"; // name of bookmark in doc
oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = GetDepositNO(DepositNo);
oBookmark = "AppDate";
oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = AppDate;
oBookmark = "Title";
oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = Title;
oBookmark = "ApplicantName";
oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = ApplicantName;
oBookmark = "AgentName";
oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = AgentName;
oBookmark = "Address";
oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = Address;
oBookmark = "AgentName01";
oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = AgentName;
oBookmark = "Times";
oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = Times;
oBookmark = "NumOfElements";
oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = NumOfElements;
oBookmark = "txtElements";
oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = txtElements;
oBookmark = "txtRecency";
oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = txtRecency;
oBookmark = "txtInventiveStep";
oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = txtInventiveStep;
oBookmark = "txtImplemented";
oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = txtImplemented;
oBookmark = "ElementsC";
oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = ElementsC;
oBookmark = "ElementsD1";
oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = ElementsD1;
oBookmark = "ElementsD2";
oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = ElementsD2;
oBookmark = "txtBoxPage";
oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = txtBoxPage;
oBookmark = "Fees";
oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = Fees;
oBookmark = "DepositNO01";
oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = GetDepositNO01(DepositNo);
oBookmark = "ExamTime";
oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = ExamTime;
oBookmark = "ExamTime01";
oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = ExamTime;
object saveFileName = "D:\\_Documents\\Form15\\" + "Form15 " + DepositNo.ToString() + "_" + randomInt.ToString() + ".docx";
oDoc.SaveAs(ref saveFileName, 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);
私が取り組んでいたことを知っている: Visual Studios C# 2010、および Microsoft .NET Framework 4.0 サーバー上: Visual Studio C# 2005、MS Framework 2.0
何が問題なのですか?