|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Applying word styles using VB .Net using up too much memory and is slowdocument. I loop through each element in the xml document and type it out in the word document, as I type out each element of text I apply the relevant style to it like so: With m_objselection .Style = strFormat .TypeText(strText) End With m_objselection is my current selection and strFormat is the name of the style I want to apply. This is a very slow process, when I watch the Winword.exe process in the task manager the memory usage just goes up and up till it runs out of memory and can't complete the document. If I remove the bit where I set the style the compiler whizzes through and converts the document in no time at all, e.g.: With m_objselection ' .Style = strFormat .TypeText(strText) End With Is there some way of freeing up the memory word is using to apply each style and speed up the process? Thanks Kay How are you creating the m_objselection and do you clean up references with
Marshal.ReleaseComObject (xxx) afterwards? You might be inadvertently creating a new selection object on each iteration, without releasing the previous one. <kayrog***@yahoo.com> wrote in message Show quoteHide quote news:1148462419.480386.33680@j55g2000cwa.googlegroups.com... >I have an XML document that I am looping through to generate a word > document. I loop through each element in the xml document and type it > out in the word document, as I type out each element of text I apply > the relevant style to it like so: > > With m_objselection > .Style = strFormat > .TypeText(strText) > End With > > m_objselection is my current selection and strFormat is the name of the > style I want to apply. > > This is a very slow process, when I watch the Winword.exe process in > the task manager the memory usage just goes up and up till it runs out > of memory and can't complete the document. > > If I remove the bit where I set the style the compiler whizzes through > and converts the document in no time at all, e.g.: > > With m_objselection > ' .Style = strFormat > .TypeText(strText) > End With > > Is there some way of freeing up the memory word is using to apply each > style and speed up the process? > > Thanks > > Kay > I create the word object refernce, then I create the word document,
then I create m_objSelection: Dim objWordDoc As New Word.Document m_objWord = New Word.Application objWordDoc = m_objWord.Documents.Add() objWordDoc = m_objWord.ActiveDocument m_objselection = m_objWord.Selection I then loop through my existing XML document and build up the word document. The m_objselection is not set nothing till the end of the document, I use it to type the word document out as you would manually setting styles and writing text, paragraphs etc. I think if I set the m_objselection to nothing after every time I write something out then I will lose my place in the document. I was wondering if I could maybe set the style then free up the memory that is used to set the style some how straight after. Or if there is another way of doing this. I have not come across Marshal.ReleaseComObject (xxx) before, I just had a look at teh msdn for it and I don't really understand it, could tell me a bit more about it or point me in teh direction of some help on it please. Thanks Kay
DataRelation vs DataView.RowFilter property
Creating a "Back" button in VB.Net/ASP.Net Project won't run from network drive. Postmessage API Can't get true random numbers application.exit( ) Wierd .NET Debugging behavior... Referencing Images... Comparing Two DataTables How to find all CD/DVD & CD/DVD-RW drives? |
|||||||||||||||||||||||