Record Office Add-in development experience, officeadd-in

Source: Internet
Author: User

Record Office Add-in development experience, officeadd-in

Original article reprinted please indicate the source: @ cosi, http://zeeman.cnblogs.com

Thanks to Microsoft's powerful common capabilities and Visual Studio development support, it is not difficult to implement Office plug-ins. One experience record is as follows:

1. If you want to develop both the Word and Outlook plug-ins, you can close the reusable code to an independent Library.

2. You can embed the WPF component on a system that can install. NET Framework 4.

3. Due to the Office security model, the signature of the trusted certificate is required during installation and deployment.

4. The initialization code can be added in ThisAddIn, such as Startup, Shutdown, and Application. NewMailEx...

 

Code highlights

1. Get the file name:

app = Globals.ThisAddIn.Application;Path.GetExtension(app.ActiveDocument.FullName)

 

2. Check whether the document is saved:

app = Globals.ThisAddIn.Application;if (!app.ActiveDocument.Saved){    if (MessageBox.Show("This command publish the disk version of a file to the server. Do you want to save your changes to disk before proceeding?", "warning",        MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)    {        try        {            app.ActiveDocument.Save();            MessageBox.Show("save succeeded", "information", MessageBoxButtons.OK, MessageBoxIcon.Information);        }        catch (Exception ex)        {            MessageBox.Show("saved failed." + ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);            return;        }    }}

 

3. Get the document content and add your own information

Public byte [] GetDocumentContent (Word. Document wordDoc, string headerText, string footerText) {// some formats are lost when you use Mail. RTFBody to retrieve the Document content, so the clipboard method is used here. // Copy the document content to the clipboard wordDoc. content. copy (); using (RichTextBox rtb = new RichTextBox () {// Add the header information rtb. appendText (headerText); rtb. selectAll (); rtb. selectionFont = new Font ("Courier New", 11); rtb. selectionColor = Color. green; // Add the text rtb. select (rtb. textLength, 0); rtb. paste (); Clipboard. clear (); // Add the tail information rtb. selectionFont = new Font ("Courier New", 11); rtb. selectionColor = Color. green; rtb. appendText (footerText); using (System. IO. memoryStream stream = new MemoryStream () {rtb. saveFile (stream, RichTextBoxStreamType. richText); return stream. toArray ();}}}

 

4. Convert outlook mail body to Word documents:

object selObject = currentExplorer.Selection[1];MailItem mail = selObject as MailItem;if (mail == null){    MessageBox.Show("non-mail item not supported.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);    return;}Word.Document wordDoc = (Word.Document)mail.GetInspector.WordEditor;

 

Download Resources

Office Control Identifiers: http://www.microsoft.com/en-us/download/details.aspx? Id = 6627

Office Document Extractor: http://code.msdn.microsoft.com/office/CSOfficeDocumentFileExtract-e5afce86


Microsoft Office File Validation Add-in

About Office 2010 file Verification

The Office security team is responsible for testing Office file verification (code name: Gateway Guard ). There are some misunderstandings about the new file verification feature in Microsoft Office 2010. Here I want to eliminate these misunderstandings and describe the causes and specific operations.

1. What is Office 2010 file verification?

Office file verification is a precaution. It mainly checks the application, that is, the number of digits of the parsed file. If it is determined to be a valid file, it will be opened normally. If it is found that the file is invalid, it will be sent to the protected view (by default.

2. What is gateway guard?

Office file verification is a feature first introduced in Publisher 2007 to verify the PUB file of Publisher. It verifies whether a specific binary file meets application requirements. This feature is effectively extended in Office 2010 in binary formats including Word, Excel, and PowerPoint. Note that this function is only applicable to binary formats (PUB, DOC, XLS, PPT, and so on), and cannot verify XML-based documents (docx, XLSX, and PPT ), you cannot verify macros or other custom projects. The object that can be verified is the file structure.

3. Why is verification required?

For a long time, the standard of the Office binary format is constantly evolving, and the complexity is constantly increasing. The reasons for the complexity of these formats have been discussed in detail elsewhere (refer to the Joel Spolsky article on the 2 and 3 floors). Therefore, we will not discuss them here, however, these binary formats are well documented here. Malicious attackers use binary files as attack methods to infect target users. Therefore, we hope to find a way to prevent this problem. The gateway Guard performs a verification check when Microsoft receives a report of attacks against a new Office file format to understand the effectiveness of this measure. So far, the results have been quite good!

4. How to control the verification?

1. Pass Policy
Use group policies to control default operations when file verification fails. These policies are located in the options, security, trust center, and protected view of the application in the Group Policy template, depending on the application settings.

2. Use the Registry
There are several registry entries used to control all aspects of Office file authentication.

Common registry items
HKCU \ Software \ Microsoft \ Office \ 14.0 \ Common \ Security \ FileValidation \ ReportingInterval-this is a DWORD that controls the number of days between the displayed dialog box that sends files to the Windows Error Report.
HKCU \ Software \ Microsoft \ Office \ 14.0 \ Common \ Security \ FileValidation \ DisableReporting-this is a DWORD. If it is set to 1, the dialog box is not displayed. Therefore, you are not allowed to send files to Windows error reports ).

Application-specific registry entry
This applies to the examples I will use "Excel", but is equally valid for "PowerPoint" and "Word"
HKCU \ Software \ Microsoft \ Office \ 14.0 \ Excel \ Security \ FileValidation \ EnableOnLoad-this is a DWORD. If it is set to 0, the Office will not verify ...... remaining full text>

C # When developing Office Add-In, the NET version should be faulty.

What versions will your users use in the future? Focuses on their needs
2007 is a general trend, but it is not widely used now, and the operational habits need to be changed too much. 03 is very popular, but the functions are obviously not as powerful as 07, And the stamina is not as good as 07

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.