Independentsoft
Any library, any programming language
Home
Purchase
Support
Company
Contact
ODF .NET
>
Tutorial
> Set field value
The following example shows you how to set SimpleVariableSetField field value.
C# example
using System; using System.Collections.Generic; using Independentsoft.Office.Odf; using Independentsoft.Office.Odf.Fields; namespace Sample { class Program { static void Main(string[] args) { TextDocument doc = new TextDocument("c:\\test\\input.odt"); IList
paragraphs = doc.GetParagraphs(); for (int i = 0; i < paragraphs.Count; i++) { for (int j = paragraphs[i].Content.Count - 1; j >= 0; j--) { if (paragraphs[i].Content[j] is SimpleVariableSetField) { SimpleVariableSetField field = (SimpleVariableSetField)paragraphs[i].Content[j]; if (field.Name == "CustomerID") { field.Value = "12345"; } } } } doc.Save("c:\\test\\output.odt", true); } } }
VB example
Imports System Imports System.Collections.Generic Imports Independentsoft.Office.Odf Imports Independentsoft.Office.Odf.Fields Module Module1 Sub Main(ByVal args() As String) Dim doc As New TextDocument("c:\test\input.odt") Dim paragraphs As IList(Of Paragraph) = doc.GetParagraphs() For i As Integer = 0 To paragraphs.Count - 1 For j As Integer = paragraphs(i).Content.Count - 1 To 0 Step -1 If TypeOf paragraphs(i).Content(j) Is SimpleVariableSetField Then Dim field As SimpleVariableSetField = DirectCast(paragraphs(i).Content(j), SimpleVariableSetField) If field.Name = "CustomerID" Then field.Value = "12345" End If End If Next Next doc.Save("c:\test\output.odt", True) End Sub End Module
Need help? Ask our developers:
Name*
Email*
Message*