J
Jim
Hi everybody.
I have a custom reports functionality in my application. It is
basically Word document with bunch of bookmarks. In my code, I open
that document and return data from SQL to that file.
It works fine. The only problem is doesn't matter how I changed the
format of my template docuemnt, when I open it for specific data, all
the formattings get lost, such as font size, italic, bold and etc. Th
estrangest thing is the whole line after the bookmark is get set to the
format which it is supposed to be, but not the bookmark itself. It
seems to be locked. And you can not really change it's format. So, if
anyone has any idea how to make it to work properly, I would really
appreciate it
Here is my code:
Dim hash As New Hashtable()
Dim tmp As String, value As String
Dim objWord As New Word.Application()
Dim objDoc As Word.Document
objDoc = objWord.Documents.Add(Folder + "\" + mFileName)
Dim field As Word.Field
For Each field In objDoc.Fields
tmp = field.Code.Text.Trim
value = GetValue(tmp)
If Not hash.Contains(tmp) Then
hash.Add(tmp, value)
End If
Next
For Each tmp In hash.Keys
field = objDoc.Fields.Add(objWord.Selection.Range, , "SET " & tmp &
" """ & hash.Item(tmp) + """", )
Next
objDoc.Fields.Update()
objWord.ActiveWindow.View.ShowFieldCodes = False
objWord.Visible = True
Thanks.
I have a custom reports functionality in my application. It is
basically Word document with bunch of bookmarks. In my code, I open
that document and return data from SQL to that file.
It works fine. The only problem is doesn't matter how I changed the
format of my template docuemnt, when I open it for specific data, all
the formattings get lost, such as font size, italic, bold and etc. Th
estrangest thing is the whole line after the bookmark is get set to the
format which it is supposed to be, but not the bookmark itself. It
seems to be locked. And you can not really change it's format. So, if
anyone has any idea how to make it to work properly, I would really
appreciate it
Here is my code:
Dim hash As New Hashtable()
Dim tmp As String, value As String
Dim objWord As New Word.Application()
Dim objDoc As Word.Document
objDoc = objWord.Documents.Add(Folder + "\" + mFileName)
Dim field As Word.Field
For Each field In objDoc.Fields
tmp = field.Code.Text.Trim
value = GetValue(tmp)
If Not hash.Contains(tmp) Then
hash.Add(tmp, value)
End If
Next
For Each tmp In hash.Keys
field = objDoc.Fields.Add(objWord.Selection.Range, , "SET " & tmp &
" """ & hash.Item(tmp) + """", )
Next
objDoc.Fields.Update()
objWord.ActiveWindow.View.ShowFieldCodes = False
objWord.Visible = True
Thanks.