在Word文档中添加签名行

时间:2018-10-02 03:11:47

标签: c# ms-word office-interop digital-signature

我正在开发一个程序,以自动向Word文档添加数字签名。在搜索时,我想到了这个答案(source):

schoolID    SAT_code    student_name
ABC                     Jasmine Smith
ABC                     Michael Jordan
ABC                     Madison Trump
XYZ                     Sarah Potter
XYZ                     Jim Fowler
XYZ                     Jack Black
 .                          .
 .                          .
 .                          .

此方法的工作原理:

  1. 打开Word应用程序

  2. 打开文档(使用data stateSAT; set statestats; if schoolID eq 'ABC' then SAT_code 'East'; else if schoolID eq 'XYZ' then SAT_code 'Midwest'; else if schoolID eq 'MNO' then SAT_code 'East'; and so forth..... run; private void CreateNewPage() { object missing = System.Reflection.Missing.Value; object fileName = @"F:\Doc\test.docx"; object readOnly = false; object isVisible = true; //Start Word and open a document. Microsoft.Office.Interop.Word._Application oWord; Microsoft.Office.Interop.Word._Document oDoc; oWord = new Microsoft.Office.Interop.Word.Application(); oWord.Visible = true; oDoc = oWord.Documents.Open(ref fileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing); // var numberOfPages = oDoc.ComputeStatistics(Word.WdStatistic.wdStatisticPages, false); object oEndOfDoc = "\\endofdoc"; object paramNextPage = Microsoft.Office.Interop.Word.WdBreakType.wdSectionBreakNextPage; oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range.InsertBreak(ref paramNextPage); //Insert a page break object breakPage = Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak; object saveOption = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges; object originalFormat = Microsoft.Office.Interop.Word.WdOriginalFormat.wdOriginalDocumentFormat; object routeDocument = false; object what = Microsoft.Office.Interop.Word.WdGoToItem.wdGoToPage; object which = Microsoft.Office.Interop.Word.WdGoToDirection.wdGoToLast; object count = 3; oWord.Selection.GoTo(ref what, ref which, ref count, ref missing); object sigID = "{00000000-0000-0000-0000-000000000000}"; try { oWord.Activate(); SignatureSet signatureSet = oWord.ActiveDocument.Signatures; // signatureSet.ShowSignaturesPane = false; Signature objSignature = signatureSet.AddSignatureLine(sigID); objSignature.Setup.SuggestedSigner = "docSigner"; objSignature.Setup.SuggestedSignerEmail = "abc@xyz.com"; objSignature.Setup.ShowSignDate = true; // dynamic shape = objSignature.SignatureLineShape; } catch (Exception ex) { MessageBox.Show(ex.Message); } oWord.Documents.Save(); oWord.Quit(); try { Marshal.ReleaseComObject(oWord); } catch (Exception e) { MessageBox.Show(e.Message); } }

  3. 获取文档书签的结尾(使用readOnly = false并插入分页符

  4. 转到最后一页(我想)

  5. 添加签名行

  6. 保存文档并退出应用程序

总而言之,此方法在文档末尾创建一个新页面并添加签名行。

我在代码的以下部分遇到麻烦:

  • isVisible = true是什么?它与签名行有什么关系?

  • 如果您偶然知道,为什么作者必须声明oEndOfDocsigIDsaveOption而不使用它?

  • 如果最后退出了应用程序,变量originalFormat是否重要?

  • 我是否正确理解此代码?

很抱歉问了太多问题,但是代码已经出现了一段时间的错误。

0 个答案:

没有答案