Free Support Forum - aspose.com

Reference problem to Aspose.Words

Hi,

I downloaded Aspose.Words for evaluation. I installed it on my machine and then added a reference to Aspose.Words. Now when I do an imports in my VB code as well as getting Aspose in my imports dropdown list I also get Xenocode and followed by 30 or so entries of square boxes. Can somebody tell me what amy be happening here?

Aspose.Words version is 3.7.1.0

Also one of the things I need to do is replace a bookmark from my document with table generated by my code. Can somebody point me to some sample code.

Thanks,

Balvinder

For evaluation I would rather recommend Aspose.Words 4.0 beta download as it has a number of new and exciting features there.

The issue with Xenocode was reported by a number of customers. Please refer to the following thread for additional information:

http://www.aspose.com/Community/forums/54544/ShowThread.aspx#54544

We can do nothing from our side at the moment, the problem needs to be fixed by obfuscation engine producers.

Concerning replacing bookmark from with generated table please hang on. I will compose an example and post it here shortly.

Best regards,

Ok. here is a code for building table at the specified bookmark:

public void TestBuildTableAtBookmark()

{

Document doc = TestUtil.Open("Doc1.doc");

Bookmark bookmark = doc.Range.Bookmarks["bookmarkName"];

// If bookmark contains any text, the remove it before insertion.

bookmark.Text = "";

AddTableBeforeNode(bookmark.BookmarkEnd);

// Save the results.

string filenameOut = "Doc1 Out.doc";

doc.Save(filenameOut);

// Open the resulting file in MS Word to test results.

System.Diagnostics.Process.Start(filenameOut);

}

private void AddTableBeforeNode(Node node)

{

DocumentBuilder builder = new DocumentBuilder(node.Document);

// builder is positioned to the node

builder.MoveTo(node);

// use builder to insert table

builder.RowFormat.Borders.LineStyle = LineStyle.Single;

builder.StartTable();

builder.InsertCell();

builder.Write("Text1");

builder.InsertCell();

builder.Write("Text2");

builder.EndRow();

builder.EndTable();

}

Hope it helps,

Thank you for a quick reply. As per your earlier reply I have downloaded v4.0Beta and installed it on my machine. Since eta is just few days away as I have read in one of the forum entries.

I have also tried building the table like you told me in your code but I am getting little strange results. Can I somehow send you the resulting document and maybe you can tell me what I am doing wrong. But here is the code I used to build my table. Basically it builds a 3 column table where the 1st and 3rd column has data and the middle column is blank which will allow me to control the seperation between column 1 and 3.

Private Sub BuildLabTable(ByVal node As Node, ByVal programId As Integer)

Dim oProgramServiceProvider As daProgServiceProvider = New daProgServiceProvider

Dim dsl As DataSet

Dim drl As DataRow

Dim oServiceProvider As daServiceProvider = New daServiceProvider

Dim docBuilder As DocumentBuilder

Dim iLabCount As Integer = 0

Dim iTableRow As Integer = 0

Dim iTableColumn As Integer = 0

dsl = oProgramServiceProvider.GetProgramServiceProviderListByProgramIdOrderedDS(daServiceType.Laboratory, programId, "")

docBuilder = New DocumentBuilder(node.Document)

docBuilder.MoveTo(node)

docBuilder.StartTable()

Dim iLabNumber As Integer = 0

For Each drl In dsl.Tables(0).Rows

oServiceProvider.GetServiceProvider(drl("service_provider_id"))

iTableRow = iLabNumber \ 2 + 1

iTableColumn = iLabNumber Mod 2

If iTableColumn = 1 Then

iTableColumn = 3

Else

iTableColumn = 1

End If

docBuilder.InsertCell()

If oServiceProvider.Name.Length > 0 Then

docBuilder.Write(oServiceProvider.Name + Environment.NewLine())

End If

If oServiceProvider.AddressLine1.Length > 0 Then

docBuilder.Write(oServiceProvider.AddressLine1 + Environment.NewLine())

End If

If oServiceProvider.AddressLine2.Length > 0 Then

docBuilder.Write(oServiceProvider.AddressLine2 + Environment.NewLine())

End If

If iTableColumn = 1 Then

docBuilder.InsertCell()

Else

docBuilder.EndRow()

End If

iLabNumber += 1

Next

If iTableColumn = 1 Then

docBuilder.InsertCell()

docBuilder.EndRow()

End If

docBuilder.EndTable()

End Sub

Yes, please attach the resulting file. Go to the 'Options' tab of the post editor to attach a file to the composed post.

You can also make the desired table in MS Word and attach the document with it here. I will compose the code required to build it in Aspose.Words for you.

Best regards,

Hi There,

I have attached the output word document for you to look at. I viewed it using MS Word 2003 Under the heading

3 Participating Laboratories: (Page 2)

I was expecting the table output to look like

Bal Lab Corp 1 Bal Lab Corp 2

Bal Lab Corp 3

But the output I got was

Bal Lab Corp 1 Bal Lab Corp 2 Bal Lab Corp 3

Thanks,

Balvinder

The logic in your code seems a bit complicated. Try to debug and check if EndRow calls actually occur where expected.

Best regards,

Hi,

Yes a little bit but it works. I single stepped through my code and it did the right thing. That is it did call EndRow at the right time. I did the code very quickly to test some of the functionality I needed. I can make it little less complicated, add comments and send it to you again if you want.

Balvinder

Hi Again,

Here is the modified code

Private Sub BuildLabTable(ByVal node As Node, ByVal programId As Integer)

Dim oProgramServiceProvider As daProgServiceProvider = New daProgServiceProvider

Dim dsl As DataSet

Dim drl As DataRow

Dim oServiceProvider As daServiceProvider = New daServiceProvider

Dim docBuilder As DocumentBuilder

Dim iLabNumber As Integer = 0

Dim iTableColumn As Integer = 0

'Get list of lab for a given program

dsl = oProgramServiceProvider.GetProgramServiceProviderListByProgramIdOrderedDS(daServiceType.Laboratory, programId, "")

'Init docBuilder with the document

docBuilder = New DocumentBuilder(node.Document)

'Move to the bookmark we want

docBuilder.MoveTo(node)

'Start a new table. This table will have 3 columns. Column 1 and 3 will have lab information

'and column 2 will be used for spacing between column 1 and 3

docBuilder.StartTable()

'For each lab

For Each drl In dsl.Tables(0).Rows

'Get detail info for the lab

oServiceProvider.GetServiceProvider(drl("service_provider_id"))

iLabNumber += 1

'Set the column number to the colunm we will be writing the lab data to.

'If lab number is odd then we will be writing to column 1 else we will be writing to column 3

iTableColumn = iLabNumber Mod 2

If iTableColumn = 1 Then

iTableColumn = 1

Else

iTableColumn = 3

End If

'Inset a new table cell and write the lab data into it

docBuilder.InsertCell()

If oServiceProvider.Name.Length > 0 Then

docBuilder.Write(oServiceProvider.Name + Environment.NewLine())

End If

If oServiceProvider.AddressLine1.Length > 0 Then

docBuilder.Write(oServiceProvider.AddressLine1 + Environment.NewLine())

End If

If oServiceProvider.AddressLine2.Length > 0 Then

docBuilder.Write(oServiceProvider.AddressLine2 + Environment.NewLine())

End If

'If we have just written to column 1 then insert a blank column. This is column 2 spaceing

'If we have just written to column 3 then end this row

If iTableColumn = 1 Then

docBuilder.InsertCell()

Else

docBuilder.EndRow()

End If

Next

'If we have just written to column 1 then we need to complete the row by inserting blank cell

'for column 3 and ending the row.

If iTableColumn = 1 Then

docBuilder.InsertCell()

docBuilder.EndRow()

End If

'Finish off the table

docBuilder.EndTable()

End Sub

In your document the table rows are created correctly but are put side-by-side because the section you are inserting in is set to two-columns mode. I mean two text columns, not table columns. Please check you template document and remove the 2-columns setting. Or attach it here, I will look at it myself.

Best regards,

Hi There,

Thank you very much for pointing that out to. Indead you are correct about the 2 column text. I got it under control now.

Once again thank you,

Balvinder