none
Problem with punctuation mark when converting word to txt RRS feed

  • Question

  • Hi,

    I'm facing a problem when trying to convert a word to srt file \ txt file .

    When the word's text is written in hebrew , the convert changes some of the punctuation mark location .

    For example:

    "?מה קורה פה"

    converts to:

    ?"מה קורה פה"

    another example

    ."אז אומרים לי, "אבות

    converts to

    ".אז אומרים לי, "אבות

     

    This my test application :

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Word = Microsoft.Office.Interop.Word;
    using Microsoft.Office.Interop;
    using Microsoft.Office.Core;
    
     
    
    namespace ConvertWordToSrt
    {
        class Program
        {
            static void Main(string[] args)
            {
    
                var wordApp         = new Word.Application();
    
                object source       = @"C:\Users\HP\Desktop\tt.doc";
                object target       = @"C:\Users\HP\Desktop\tt2.srt";
    
                object format       = Word.WdSaveFormat.wdFormatText;
                var unknown         = Type.Missing;
                object encoding     =   MsoEncoding.msoEncodingHebrew;
               
               
    
                wordApp.Documents.Open(ref source, ref unknown, ref unknown,
                                       ref unknown,ref unknown, ref unknown,
                                       ref unknown, ref unknown, ref unknown,
                                       ref unknown, ref encoding, ref unknown,
                                       ref unknown, ref unknown, ref unknown);
    
                wordApp.ActiveDocument.SaveAs(ref target, ref format,
                            ref unknown, ref unknown, ref unknown,
                            ref unknown, ref unknown, ref unknown,
                            ref unknown, ref unknown, ref unknown,
                            ref encoding, ref unknown, ref unknown,
                            ref unknown, ref unknown);
    
                // for closing the application
    
                wordApp.Quit(ref unknown, ref unknown, ref unknown);
    
    
            }
        }
    }
    
    


    Kind Regards,

    Tal Humy

     

     

    • Moved by Cindy Meister MVPModerator Thursday, October 27, 2011 12:03 PM not using VSTO technology (From:Visual Studio Tools for Office)
    Thursday, October 27, 2011 11:22 AM

Answers

All replies

  • Hi Tal,

    How about the problem on your side? I test your code snippt on my side, however, I can't reproduce the scenario as you described. How did you open the srt file? I try to open it via notepad, but it shows unreadable code and the punctuation mark locations do not change.

    What is the version of your Word application?

    Best Regards,

     


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, October 31, 2011 9:07 AM
  • Hi Bruce ,

    Thank you for your help.

    I open srt files with subtitles workshop  - its a free software.

    I think the reason that you see unreadable code is because the encoding is set to hebrew language.

    Thursday, November 3, 2011 12:59 PM
  • Hi Tal,

    As far as I know, the SaveAs funciton can not save the file as you mentioned format srt. I think this may be the reason of your problem. Please take a look at the reference on MSDN:

    http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.wdsaveformat.aspx

    Try to save it as wdFormatText to see whether works well. Hope this suggestion can help you.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Edited by Bruce Song Friday, November 4, 2011 9:06 AM
    • Proposed as answer by Shasur Friday, November 4, 2011 9:22 AM
    • Marked as answer by Bruce Song Monday, November 7, 2011 7:52 AM
    Friday, November 4, 2011 9:05 AM