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

Free Support Forum - aspose.com

English statment is overturned in Arabic report

Dear Aspose,

I’m having an Arabic report that retrieves data from the database and generate a word document based on a predefined template files.

the issue appears Under Arabic reports, when I want to show an english statment has an english numbers (ex:- "Information Test 2") the result will be overturned like "2 Information Test".

Please advise,

Note : I’m using office word 2007.

Thanks,

Hello,

Thank you for your request.
Could you please give us your template and the code that you use. We will analyze them and provide you with more detailed information.

Hello

Please find the attached file it contains a sample project from my code.

Thanks

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. The problem occurs because you applying Bidi option for English text. You can work the problem around by resetting this option for English text. I created a simple code example that demonstrates how to achieve this using IFieldMergingCallback.

_

Public Sub Test001()

Dim OtherTempdt As New DataTable("MyTable")

OtherTempdt.Columns.Add("الاسم", GetType(String))

OtherTempdt.Columns.Add("الرقم", GetType(String))

OtherTempdt.Rows.Add("Information Test 4", "0124578")

OtherTempdt.Rows.Add("الرقم", "0124578")

Dim TempDoc As New Document("C:\Temp\contactlistA.docx")

For Each Section As Section In TempDoc.Sections

For Each srcNode As Node In Section

Dim runs As NodeCollection = Section.GetChildNodes(NodeType.Run, True)

For Each run As Run In runs

run.Font.Size = 10

run.Font.Name = "Times New Roman"

run.Font.NameBi = "Times New Roman"

run.Font.SizeBi = 10

run.Font.Bidi = True

Next

Next

Next

TempDoc.MailMerge.FieldMergingCallback = New FieldMergingCallback()

TempDoc.MailMerge.ExecuteWithRegions(OtherTempdt)

TempDoc.Save("C:\temp\out.doc")

End Sub

Private Class FieldMergingCallback

Implements IFieldMergingCallback

Public Sub FieldMerging(ByVal args As FieldMergingArgs) Implements IFieldMergingCallback.FieldMerging

' We need to check whther field value contains any arabic cars.

' in this case we will enable Bidi option othervice disable it.

Dim fieldValue As String = args.FieldValue.ToString()

' Create Documentbuilder to insert a value at the mergefield.

Dim builder As New DocumentBuilder(args.Document)

' move DocumentBuilder cursor to the mergefield.

builder.MoveToField(args.Field, True)

' set or reset Bidi option.

builder.Font.Bidi = arabicCharsRegex.IsMatch(fieldValue)

Console.WriteLine(builder.Font.Bidi)

builder.Write(fieldValue)

' reset text of the field because we alredy inserted the value.

args.Text = ""

End Sub

Public Sub ImageFieldMerging(ByVal args As ImageFieldMergingArgs) Implements IFieldMergingCallback.ImageFieldMerging

' do nothing here.

End Sub

' This regular expression is used to find any arabic characters in the string.

Dim arabicCharsRegex As Regex = New Regex("[\u0600-\u06ff]|[\u0750-\u077f]|[\ufb50-\ufc3f]|[\ufe70-\ufefc]")

End Class

I used regular expression to detect whether text contains any Arabic characters.

Best regards,

Many Thanks Alexey it is working fine now

Dear Aspose,

The above issue is appearing with a new scenario , when I try to print a mixed statement ( I mean a statement contains both languages Arabic and English) the English word will be reversed.

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Please check the attached file as a sample.

Thanks,

Hi Mohd,

Thanks for your request. But I cannot reproduce the problem on my side using the latest version of Aspose.Words. As I can see you are using 5.2.0 version of Aspose.Words. Have you tried using the latest version? You can download it from here:

http://www.aspose.com/community/files/51/.net-components/aspose.words-for-.net/category1188.aspx

The problem seems to occur because Arabic and English text are in the same Run in your document. To make it work with old version, you should split Arabic and English text into separate runs. You can achieve this using the similar technique as demonstrated here:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/howto-find-and-highlight-text.html

Best regards,