private static void ResetNumbering(DocumentVariable variables, int startLevel) { for (int i = startLevel; i < MaxLevel; i++) { var levelString = Levels[startLevel]; variables[levelString][Number].SetValue(0); } }
private static List <TableEntry> GetEntryTable(DocumentVariable variables) { var toc = variables[DocumentVariables.TableOfContent]["entries"]; var list = toc.GetValue <List <TableEntry> >(); if (list == null) { list = new List <TableEntry>(); toc.SetValue(list); } return(list); }
static void Main(string[] args) { string path = @"This should be the path to your document"; using (WordprocessingDocument document = WordprocessingDocument.Open(path, true)) { DocumentVariable variable = GetVariableByName("TestVariable", document); if (variable != null) { SetDocumentVariableValue(variable, "New Value"); } // Or access the value directly // variable.Val = "New Value"; document.Save(); } }
private static void FillField(DocumentVariable vars, ObjectField field) { var value = field.Argument.Value; DocumentVariable inner; if (value is ObjectCreator subCreator) { // We can assume that the returned value is a document variable. // In every other case the Create call throws an exception. inner = (subCreator.Create(typeof(DocumentVariable), null) as DocumentVariable) !; } else { inner = new DocumentVariable(value); } vars[field.Key] = inner; }
private static string CreatePretext(DocumentVariable variables, int level) { StringBuilder sb = new StringBuilder(); string levelString = Levels[level - 1]; var current = variables[levelString][Number]; var value = current.GetValue <int>() + 1; current.SetValue(value); for (int i = 0; i < level; i++) { sb.Append(variables[levelString][Number].GetValue <int>()); if (i < level - 1) { sb.Append("."); } } return(sb.ToString()); }
/// <summary> /// Sets the value of a document variable /// </summary> /// <param name="variable">The variable</param> /// <param name="value">The value</param> public static void SetDocumentVariableValue(DocumentVariable variable, string value) { variable.Val = value; }