We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Conversion of code to Aspose syntax

Hi,
Could you please help me with the following code sniptes, converting from Word to Aspose?
'Replace Word with ASPOSE
With objWord.ActiveDocument
.TrackRevisions = False
.PrintRevisions = True
.ShowRevisions = True
End With
==================================================

Set objDoc = objWord.Documents.Open(filename:=fPathCompare)

' Set in Page Layout mode

If objWord.ActiveDocument.ActiveWindow.View.SplitSpecial = wdPaneNone Then
objWord.ActiveDocument.ActiveWindow.ActivePane.View.Type = wdPageView
Else
objWord.ActiveDocument.ActiveWindow.View.Type = wdPageView
End If

' Set page layout to landscape

With objWord.ActiveDocument.PageSetup
.Orientation = wdOrientLandscape
End With

' Select comparison table and reformat

objWord.ActiveDocument.Tables(1).Select
With objWord.Selection.Font
.Name = "Arial"
.Size = 8
End With

' Save compare file as Word document

objDoc.SaveAs filename:=fPathCompare, FileFormat:=wdFormatDocument
objDoc.Close wdDoNotSaveChanges
Set objDoc = Nothing

======================================================

Private Function cloneDoc(ByVal fPath As String) As Boolean
On Error GoTo errorFlag
' Open Word

If openWord = True Then

' Open file in Word

'Replace Word with ASPOSE
Set objDoc = objWord.Documents.Open(filename:=fPath)

' Select all

objDoc.Content.Select 'Select entire document

' Copy to clipboard

objWord.Selection.Copy 'Copy to clipboard

' Close file

objDoc.Close wdDoNotSaveChanges

' Create new Word document

Set objDoc = objWord.Documents.Add

' Paste contents of clipboard

objWord.Selection.Paste

' Save Word document

System.Windows.Forms.Application.DoEvents()
objWord.ActiveDocument.SaveAs filename:=fPath, _
FileFormat:=wdFormatDocument

' Close document and Word

objDoc.Close wdSaveChanges
Set objDoc = Nothing

'removeWord

' Couldn't open Word

Else
cloneDoc = False
Exit Function
End If

' Normal exit

cloneDoc = True
Exit Function

' Error Handling

errorFlag: 
cloneDoc = False
errorLog(Err.Description, Err.Number, "cloneDoc")

End Function

====================================================================
What is the replacement for the following code, specifically, how do we indicate the “ActiveDocument” portion of the code.
objWord.ActiveDocument.Save
----------------------------
objDoc.Close wdDoNotSaveChanges
-------------------------------
objDoc.Bookmarks("\StartofDoc").Select
’ Add bookmark
objDoc.Bookmarks.Add Name:=bName
-------------------------------------
====================================================
'KK - Replacing Word with ASPOSE

Private Function removeHeaderFooter(ByVal objDoc As Aspose.Words.Document) As Boolean
' Turn off revision tracking
With objWord.ActiveDocument
.TrackRevisions = False
.PrintRevisions = True
.ShowRevisions = True
End With
' View header
If objWord.ActiveWindow.View.SplitSpecial <> wdPaneNone Then
objWord.ActiveWindow.Panes(2).Close
End If
If objWord.ActiveWindow.ActivePane.View.Type = wdNormalView _
Or objWord.ActiveWindow.ActivePane.View.Type = wdOutlineView Then
objWord.ActiveWindow.ActivePane.View.Type = wdPrintView
End If

' Remove header text
objWord.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
objWord.Selection.WholeStory
objWord.Selection.Cut

' View footer
If objWord.Selection.HeaderFooter.IsHeader = True Then
objWord.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
objWord.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If

' Remove footer text
objWord.Selection.WholeStory
objWord.Selection.Cut
objWord.ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
objWord.ActiveWindow.ActivePane.SmallScroll Down:=-3

' Turn on change tracking
With objWord.ActiveDocument
.TrackRevisions = True
.PrintRevisions = True
.ShowRevisions = True
End With
End Function

Thanks,
Khosrow

Hi
Thanks for your request.
1. You can use TrackRevisions property to enable revision tracing. See the following link:
https://reference.aspose.com/words/net/aspose.words/document/trackrevisions/
2. You can set view type using ViewOptions property.
https://reference.aspose.com/words/net/aspose.words/document/viewoptions/
3. You can set Page orientation using PageSetup
https://reference.aspose.com/words/net/aspose.words/pagesetup/orientation/
4. Here is code that shows how to get Table from the document and change font.

// Open document
Document doc = new Document("int.doc");
// Get table
Table tab = doc.FirstSection.Body.Tables[0];
// Get collection of Runs from table
NodeCollection runs = tab.GetChildNodes(NodeType.Run, true);
foreach (Run run in runs)
{
    run.Font.Name = "Arial";
    run.Font.Size = 8;
}
  1. You can save document in DOC format using the following code:
doc.Save("out.doc", SaveFormat.Doc);
  1. You can clone document or any node using Clone method.
Document clone = (Document)doc.Clone(true);
  1. You don’t need to detect the active document. Please see the object model of Aspose.Words.
    https://docs.aspose.com/words/net/aspose-words-document-object-model/
  2. You can insert bookmark using DocumentBuilder. See the following link.
    https://docs.aspose.com/words/net/working-with-bookmarks/
  3. You can remove Header/Footer from the document using Clear method.
foreach (Section sect in doc.Sections)
{
    sect.HeadersFooters.Clear();
}

Hope this could help you.
Best regards.

Alexey,
Thanks for your speedy reply. I very much am impressed with your level of support and appreciate it.
I have a further question and that is: I have not seen in any place to close a created Doc object and releasing the resources or setting it to Nothing. Is it not needed because we are operating within .NET and it is a managed code, or, is it because how the Aspose framework has been built.
Thanks,
Khosrow

Hello!
Thank you for your inquiry.
There are no explicit methods to free resources after you finished using a Document object. Since it utilizes only memory .NET Framework will handle resources automatically. You can invoke garbage collector by your own accord to control this process a bit better. This is standard approach in .NET and you can find recommendations on when to call it on the Internet.
Regards,

Thank you for your reply.
Also, in the following code in Word, I have been able to find the equivalent conversion method in Aspose but have not been able to find for PrintRevisions and ShowRevisions . Could you please help me on this? Thanks.
'Replace Word with ASPOSE
With objWord.ActiveDocument
.TrackRevisions = False
.PrintRevisions = True
.ShowRevisions = True
End With

Hi
Thanks for your inquiry. Unfortunately there is no equivalent of these options in MS Word. Could you please tell me why you should use these options? And can you do what you need without them?
Best regards.

Hi,
Thank you for your reply.
Our document processing operations requires the ability to view and print documents with “Revision Bars” to the left-side of the paragraph or text as it gets changed by the user (both in View and Print modes). The quality assurance dept needs to be able to easily spot the document changes and approve or disapprove the change. The lack of this side-bar will be detremental to their ability to do their job properly and effectively.
If we do not have this feature we can not go forward with the project, replacing MS Word with Aspose.Word.
Thanks,
Khosrow

Hi,
I would like to elaborate further on our process:
Our Engineering dept use word to update product design documentation. They use MS Word application on their desk-tops to do this change. When they make the change the side-bar appears indicating where the change was made. This document is saved with the side-bar revision mark-ups preserved.
The next process merges many such design documents for a product into an assembly of documents for the design changes planned for the product. This merge application is developed internally and uses MS Word API. Currently the new merged document preserves the side-bar Revision Markups as well.
The next step is for the QA dept to review the total merged document for the product. They need to immediately spot the changes using the revision markups and approve or disapprove the changes.
So far I have replaced Word with Aspose.Word in a program that reads the document generated in MS Word and saves it in Aspose.Word.Doc format. The side-bar Revision Markups are not showing up.
Please help me resolve this issue as this is a very critical piece in our decision to go ahead with the full conversion (replacement of Word) and is hanging our project.
Thanks,
Khosrow

Hi
Thanks for your explanation. I used the following scenario for testing:

  1. Create simple document and enable “Track changes”
  2. Make some changes in the document and save it.
  3. Open document using Aspose.Words, disable “Track changes” and save the document
  4. Open document using Word Automation and check values of TrackRevisions, PrintRevisions, ShowRevisions Properties.
    Here is code I used for testing.
'Open document using Aspose.Words
Dim awDoc As Aspose.Words.Document = New Aspose.Words.Document("C:\Temp\in.doc")
'Disable Change Tracking
awDoc.TrackRevisions = False
'Save document
awDoc.Save("C:\Temp\out.doc")
'Create instance of Word application
Dim wordApp As Word.Application = New Word.Application()
'Open document
Dim doc As Word.Document = wordApp.Documents.Open("C:\Temp\out.doc")
'Check values
With doc
Console.WriteLine(.TrackRevisions) 'Should be "False"
Console.WriteLine(.PrintRevisions) 'Should be "True"
Console.WriteLine(.ShowRevisions) 'Should be "True"
End With
Console.ReadLine()
doc.Close()

And this core returns the following result:
False
True
True
So options PrintRevisions and ShowRevisions are enabled by default.
Regarding side-bar, if I understand you correctly you mean “Reviewing” menu of MS Word. You can enable this tool bar in MS Word (Go to “View” menu, select “Toolbars” and click “Reviewing”).
I hope this could help you.
Best regards.

Hi,
Thank you for your reply.
I am not sure if I was clear explaining our goal. In our new server environment, we would NOT have a Microsoft Word application installed**.** So, we would not be able to set any Word settings in our server application using MS Word API. We have to set ALL of our settings using Aspose API within the VB.NET dll.
Also, regarding the side bar, I was not referring to the “Reviewing” menu of MS Word. To see what I mean, please do the following:

  1. Open a MS word document on your desk top.
  2. Go to Tools : Track Change and click on it.
  3. Update or insert a few characters.
  4. You will see that those characters are in “Red” color and there is a vertical line to the left side of the paragraph. Below is a sample and I have also uploaded my test document for your viewing. In the following example, I changed “MS” to “MicroSoft” and Word changed the color of the inserted word to red and inserted a vertical line [ | ] to the left of paragraph, before “Regarding” at the beging of the paragraph.
    The above is the feature that we want to preserve when we open a word document using Aspose in our VB.NET application on the server (on which theree would NOT be any MS Word anymore). So, if somebody else schanged the document online using Aspose on the web, then I as the viewer of that document should later be able to see the changes in “Red”, with the vertical line [ | ] to the left of the changed line.
    I hope this clears the misunderstanding. Thanks.
    ===============================================================
    | Regarding side-bar, if I understand you correctly you mean “Reviewing” menu of MicroSoft Word. You can enable this tool bar in MS Word (Go to “View” menu, select “Toolbars” and click “Reviewing”)."

Hi
Thank you for additional information. Aspose.Words preserves change marks in the document. Unfortunately tracking changes made programmatically using Aspose.Words is not supported yet. This is known issue #1121.
Issue #1121 – Make it possible to track all changes made programmatically.
Best regards.

Yes, Alexey is correct. Modifications to the document that you make using Aspose.Words are NOT stored as tracking changes in the document even if the tracking changes is turned ON for the document. Modifications made using Aspose.Words are always stored as normal content and formatting. In the future we might support a mode in wich changes made using Aspose.Words are logged as tracking changes.
More info https://docs.aspose.com/words/net/track-changes-in-a-document/