/// <summary> /// set the confidential level /// </summary> /// <param name="sensitive"> confidential level string</param> private void SetWorkbookSensitive(string sensitive) { try { Microsoft.Office.Core.DocumentProperties prp = Globals.ThisAddIn.Application.ActivePresentation.CustomDocumentProperties; bool isSenitive = false; foreach (Microsoft.Office.Core.DocumentProperty documentProperty in prp) { if (documentProperty.Name.Equals("Sensitive")) { //MessageBox.Show(documentProperty.Value); //InitRabbionControl(documentProperty.Value); documentProperty.Value = sensitive; isSenitive = true; } } if (isSenitive == false) { prp.Add("Sensitive", false, Microsoft.Office.Core.MsoDocProperties.msoPropertyTypeString, sensitive, null); } Globals.ThisAddIn.InitRabbionControl(sensitive); } catch (Exception) { throw; } }
protected override void SaveCustomProperties(Dictionary <string, string> properties) { try { Office.DocumentProperties docProperties = (Office.DocumentProperties)workbook.CustomDocumentProperties; foreach (String key in properties.Keys) { foreach (Office.DocumentProperty prop in docProperties) { if (prop.Name.Equals(key, StringComparison.InvariantCulture)) { prop.Delete(); break; } } } foreach (String key in properties.Keys) { docProperties.Add(key, false, Office.MsoDocProperties.msoPropertyTypeString, properties[key], nullObjStr); } workbook.Save(); } catch (Exception e) { throw new WBOfficeErrorException("No puede obtener las propiedades del documento", e); } }
public void IUO(Office.IRibbonControl control) { Microsoft.Office.Interop.Word.Document nativeDocument = Globals.ThisAddIn.Application.ActiveDocument; Microsoft.Office.Tools.Word.Document vstoDocument = Globals.Factory.GetVstoObject(nativeDocument); Office.DocumentProperties properties = (Office.DocumentProperties)vstoDocument.CustomDocumentProperties; if (ReadDocumentProperty("Classification") != null) { properties["Classification"].Delete(); } properties.Add("Classification", false, Microsoft.Office.Core.MsoDocProperties.msoPropertyTypeString, "Internal"); foreach (Word.Section wordSection in Globals.ThisAddIn.Application.ActiveDocument.Sections) { Word.Range footerRange = wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range; footerRange.Font.ColorIndex = Word.WdColorIndex.wdDarkBlue; footerRange.Font.Size = 15; footerRange.Text = "Classification: Internal Use Only"; footerRange.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter; Word.Range headerRange = wordSection.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range; headerRange.Font.ColorIndex = Word.WdColorIndex.wdDarkBlue; headerRange.Font.Size = 15; headerRange.Text = "Classification: Internal Use Only"; headerRange.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter; } }
public static void CustomFooterExists(bool hasCustomFooter) { try { Office.DocumentProperties prps = (Office.DocumentProperties)ExcelApplication.ActiveWorkbook.CustomDocumentProperties; // Add a new property. Office.DocumentProperty prp = prps.Add("HasCustomFooter", false, Office.MsoDocProperties.msoPropertyTypeBoolean, hasCustomFooter); } catch (Exception ex) { //PLLog.Error(ex, Globals.PROJECT_NAME) MessageBox.Show("CustomFooterExists() Unable to add HasCustomFooter property" + ex.Message); } }
/// <summary> /// Finds a custom property on a word document. If it exists, deletes /// and replaces it. Else, it will add the property. /// </summary> /// <param name="stringToReplaceCustProperty"></param> public void ReplaceTestProperty(string custPropertyName, string custPropertyValue) { Office.DocumentProperties properties = (Office.DocumentProperties) this.CustomDocumentProperties; if (ReadDocumentProperty(custPropertyName) != null) { properties[custPropertyName].Delete(); } properties.Add(custPropertyName, false, Microsoft.Office.Core.MsoDocProperties.msoPropertyTypeString, custPropertyValue); }
private static Office.DocumentProperty Add(Excel.Workbook workbook, string propertyName, Office.MsoDocProperties propertyType, object value) { if (null == workbook) { throw new ArgumentNullException("workbook"); } if (string.IsNullOrWhiteSpace(propertyName)) { throw new ArgumentNullException("propertyName"); } Office.DocumentProperties properties = workbook.CustomDocumentProperties; Office.DocumentProperty property = properties.Add(propertyName, false, propertyType, value); return(property); }
protected override void SaveCustomProperties(Dictionary <string, string> properties) { try { Office.DocumentProperties docProperties = (Office.DocumentProperties)document.CustomDocumentProperties; foreach (String key in properties.Keys) { docProperties[key].Delete(); docProperties.Add(key, false, Office.MsoDocProperties.msoPropertyTypeString, properties[key], nullObjStr); } this.Save(); } catch (Exception e) { throw new WBOfficeErrorException("No puede obtener las propiedades del documento", e); } }
private void ThisDocument_BeforeSave(object sender, Microsoft.Office.Tools.Word.SaveEventArgs e) { Office.CustomXMLPart docDataSetPart = null; // Belgedeki içerik kontrol kutularıyla ilgili bilgileri içeren // veri setini belgeye ait XML alanları arasında sakla. if (docDataSetID != null) { docDataSetPart = this.CustomXMLParts.SelectByID(docDataSetID); if (docDataSetPart != null) { docDataSetPart.Delete(); } } string xmlDataSet = docDataSet.GetXml(); docDataSetPart = this.CustomXMLParts.Add(xmlDataSet); Office.DocumentProperties docProps = this.CustomDocumentProperties as Office.DocumentProperties; if (docDataSetID != null) { docDataSetID = docDataSetPart.Id; foreach (Office.DocumentProperty docprop in docProps) { if (docprop.Name == "HurTestDataSet") { docprop.Value = docDataSetID; break; } } } else { docDataSetID = docDataSetPart.Id; docProps.Add("HurTestDataSet", false, Office.MsoDocProperties.msoPropertyTypeString, docDataSetID, missing); } }