Exemplo n.º 1
0
        public static void Convert(string desFile, UnicodeConverter.Converter.ConvertOption convertOption)
        {
            TextConverter.Convert(desFile, convertOption);
            //DataSet ds = readXML(desFile);
            //int tableCount = ds.Tables.Count;
            //System.Windows.Forms.MessageBox.Show("no of table = " +tableCount);
            //for (int i = 0; i < tableCount; i++)
            //{
            //    DataTable dt = new DataTable();
            //    dt = ds.Tables[i];
            //    for (int x = 0; x < dt.Rows.Count; x++)
            //    {
            //        for (int y = 0; y < dt.Columns.Count; y++)
            //        {
            //            string xmlTxt = dt.Rows[x][y].ToString();
            //            string desTxt = UniConversion.Converter.Convert(xmlTxt, convertOption);
            //            dt.Rows[x][y] = desTxt;
            //        }
            //    }
            //    dt.EndInit();
            //}

            //ds.AcceptChanges();
            //ds.WriteXml(desFile);
            //openXmlFile(desFile);
        }
Exemplo n.º 2
0
        private void btnConvert_Click(object sender, EventArgs e)
        {
            if (txtToConvert.Text == "" || txtToConvert.Text == " ")
            {
                MessageBox.Show("Please Insert Texts to Convert!");
            }
            else if (cmbFontOption.SelectedItem == null)
            {
                MessageBox.Show("Please Select Font Option!");
            }
            else
            {
                #region Checking Font Option
                switch (cmbFontOption.SelectedIndex)
                {
                case 0: fontoption = UnicodeConverter.Converter.ConvertOption.Academy2Uni; break;

                case 1: fontoption = UnicodeConverter.Converter.ConvertOption.Amyanmar2Uni; break;

                case 2: fontoption = UnicodeConverter.Converter.ConvertOption.ATypeWriter2Uni; break;

                case 3: fontoption = UnicodeConverter.Converter.ConvertOption.Ava2Uni; break;

                case 4: fontoption = UnicodeConverter.Converter.ConvertOption.Ayar2Uni; break;

                case 5: fontoption = UnicodeConverter.Converter.ConvertOption.CE2Uni; break;

                case 6: fontoption = UnicodeConverter.Converter.ConvertOption.Gandamar2Uni; break;

                case 7: fontoption = UnicodeConverter.Converter.ConvertOption.I2Uni; break;

                case 8: fontoption = UnicodeConverter.Converter.ConvertOption.Metrix2Uni; break;

                case 9: fontoption = UnicodeConverter.Converter.ConvertOption.MMyanmar2Uni; break;

                case 10: fontoption = UnicodeConverter.Converter.ConvertOption.Myanmar12Uni; break;

                case 11: fontoption = UnicodeConverter.Converter.ConvertOption.MyaZedi2Uni; break;

                case 12: fontoption = UnicodeConverter.Converter.ConvertOption.Pinny52Uni; break;

                case 13: fontoption = UnicodeConverter.Converter.ConvertOption.Win2Uni; break;

                default: fontoption = UnicodeConverter.Converter.ConvertOption.Zawgyi2Uni; break;
                }
                #endregion

                // string convertedOutput = UnicodeConverter.Converter.Convert(txtToConvert.Text, fontoption);
                string convertedOutput = UnicodeConverter.Converter.Convert(txtToConvert.Text, fontoption);
                txtConverted.Font = myanmar3;
                txtConverted.Text = convertedOutput;
            }
        }
Exemplo n.º 3
0
        public static void Convert(string desFile, UnicodeConverter.Converter.ConvertOption convertOption)
        {
            //UniConversion.Converter.ConvertOption.
            StreamReader  sr           = new StreamReader(desFile);
            StringBuilder resultStrBil = new StringBuilder();
            string        desTxt       = string.Empty;

            while ((desTxt = sr.ReadLine()) != null)
            {
                resultStrBil.Append(UnicodeConverter.Converter.Convert(desTxt, convertOption) + "\r\n");
            }
            sr.Close();
            //desTxt = UnicodeConverter.Converter.Convert(readTxtFile(desFile), convertOption);
            writeTxtFile(resultStrBil, desFile);
            openTxtFile(desFile);
        }
Exemplo n.º 4
0
        public static void Convert(Word.Application wordApp, UnicodeConverter.Converter.ConvertOption option)
        {
            Label lbl = new Label();

            lbl.Text = "Loading ....";
            string srcTxt = wordApp.ActiveDocument.Content.Text;

            string uniTxt = UnicodeConverter.Converter.Convert(srcTxt, option);

            wordApp.ActiveDocument.Content.Text = uniTxt;

            // set "Myanmar3"to default sript name
            wordApp.ActiveDocument.Content.Font.Name = "Myanmar3";

            // set "Myanmar3"to Complex Script name
            wordApp.ActiveDocument.Content.Font.NameBi = "Myanmar3";
        } // end of Convert()
Exemplo n.º 5
0
        public static void Convert(string desFile, UnicodeConverter.Converter.ConvertOption convertOption)
        {
            //UniConversion.Converter.ConvertOption.
            StreamReader  sr           = new StreamReader(desFile);
            StringBuilder resultStrBil = new StringBuilder();
            string        desTxt       = string.Empty;

            while ((desTxt = sr.ReadLine()) != null)
            {
                resultStrBil.Append(UnicodeConverter.Converter.Convert(desTxt, convertOption) + "\r\n");
            }
            sr.Close();
            // StringBuilder sb = new StringBuilder();
            //foreach (int progress in LoadFileWithProgress(desFile, resultStrBil))
            //{
            //    // Update your progress counter here!

            //}
            ////string fileData = resultStrBil.ToString();
            ////desTxt = UnicodeConverter.Converter.Convert(readTxtFile(desFile), convertOption);
            //resultStrBil.Append(UnicodeConverter.Converter.Convert(fileData, convertOption) + "\r\n");
            writeTxtFile(resultStrBil, desFile);
            //openTxtFile(desFile);
        }
Exemplo n.º 6
0
        } // end of Convert()

        public static void Convert(String wordFilePath, UnicodeConverter.Converter.ConvertOption option, String saveFilePath)
        {
            //UniConversion.Converter.ConvertOption.
            WordXML_Utilities uti     = new WordXML_Utilities();
            String            xmlFile = uti.ConvertToXML(wordFilePath);

            Logging.logger += "Converting XML :: " + "\n";

            //Logging.logger += "wordFilePath is : " + wordFilePath + "\n";
            //Console.WriteLine("wordFilePath is : " + wordFilePath);
            // Logging.logger += "saveFilePath is : " + saveFilePath + "\n";
            //Console.WriteLine("saveFilePath is : " + saveFilePath);
            //Logging.logger += "xmlFilePath is : " + xmlFile + "\n";
            //Console.WriteLine("xmlFilePath is : " + xmlFile);

            XmlDocument doc = new XmlDocument();

            doc.Load(xmlFile);
            XmlElement  root   = doc.DocumentElement;
            string      tt     = "";
            XmlNodeList nodes1 = doc.GetElementsByTagName("w:defaultFonts");

            try
            {
                tt = nodes1[0].Attributes.GetNamedItem("w:ascii").Value;
            }
            catch (Exception ex)
            {
                tt              = "Calibri";
                Logging.logger += "UnicodeConverter.Convert().[tt = nodes1[0].Attributes.GetNamedItem(w:ascii).Value] give Error:::: " + ex.Message + "\n";
            }

            XmlNodeList nodes = doc.GetElementsByTagName("w:r");//Getting Nodelist from input XML file. w:r is node tag name
            XmlNode     LastNode;
            XmlNode     newnodetext;
            string      uniTxt = "";

            UnicodeConverter.Converter.ConvertOption fontobj = new UnicodeConverter.Converter.ConvertOption();
            fontobj = UnicodeConverter.Converter.ConvertOption.Academy2Uni;

            string[] strarr = new string[15];

            for (int i = 0; i < strarr.Length; i++)
            {
                // Adding fonts names into strarr array
                strarr[i] = fontobj.ToString().Substring(0, fontobj.ToString().LastIndexOf('2'));
                if (strarr[i] == "ATypeWriter")
                {
                    strarr[i] = "A_Type Writer";
                }
                fontobj++;
            }

            foreach (XmlNode node in nodes)
            {
                XmlNode FirstNode = node.FirstChild;
                LastNode    = node.LastChild;
                newnodetext = node.LastChild;
                string t2 = LastNode.InnerText;

                try
                {
                    tt = FirstNode.FirstChild.Attributes.GetNamedItem("w:ascii").Value;
                    //       tt = FirstNode.FirstChild.Attributes.GetNamedItem("w:val").Value;
                }
                catch (Exception ex)
                {
                    tt              = "Times New Roman";
                    Logging.logger += "UnicodeConverter.Convert() [tt = FirstNode.FirstChild.Attributes.GetNamedItem(w:ascii).Value;] give Error:::: " + ex.Message + "\n";
                }

                for (int j = 0; j < strarr.Length; j++)
                {
                    try
                    {
                        // check fonts name in tt is equals to one of the names of strarr

                        //if (tt == "A_Type Writer")
                        //{
                        //    uniTxt = UnicodeConverter.Converter.Convert(t2, UnicodeConverter.Converter.ConvertOption.ATypeWriter2Uni);
                        //}
                        if (tt.Contains(strarr[j]))
                        {
                            if (tt == "I")
                            {
                                uniTxt = UnicodeConverter.Converter.Convert(t2, UnicodeConverter.Converter.ConvertOption.I2Uni);
                            }
                            else if (tt == "A_Type Writer")
                            {
                                uniTxt = UnicodeConverter.Converter.Convert(t2, UnicodeConverter.Converter.ConvertOption.ATypeWriter2Uni);
                            }
                            else if (tt == "Gandamar Letter 1" || tt == "Gadamar-Letter 1")
                            {
                                uniTxt = UnicodeConverter.Converter.Convert(t2, UnicodeConverter.Converter.ConvertOption.Gandamar2Uni);
                            }
                            else if (tt.Substring(0, 6).Equals("Metrix") || tt.Substring(1, 6).Equals("Metrix"))
                            {
                                uniTxt = UnicodeConverter.Converter.Convert(t2, UnicodeConverter.Converter.ConvertOption.Metrix2Uni);
                            }
                            else if (tt.Substring(0, 3).Equals("Win") || tt.Substring(1, 3).Equals("Win"))
                            {
                                uniTxt = UnicodeConverter.Converter.Convert(t2, UnicodeConverter.Converter.ConvertOption.Win2Uni);
                            }
                            else if (tt.Substring(0, 2).Equals("CE"))
                            {
                                uniTxt = UnicodeConverter.Converter.Convert(t2, UnicodeConverter.Converter.ConvertOption.CE2Uni);
                                //uniTxt = UniConversion.Converter.Convert(t2, UniConversion.Converter.ConvertOption.Win2Uni);
                            }
                            else if (tt.Contains("Myanmar"))
                            {
                                if (tt.Contains("M-Myanmar"))
                                {
                                    uniTxt = UnicodeConverter.Converter.Convert(t2, UnicodeConverter.Converter.ConvertOption.MMyanmar2Uni);
                                }
                                else
                                {
                                    uniTxt = UnicodeConverter.Converter.Convert(t2, UnicodeConverter.Converter.ConvertOption.Myanmar12Uni);
                                }
                            }
                            else
                            {
                                UnicodeConverter.Converter.ConvertOption temp = (UnicodeConverter.Converter.ConvertOption)j;
                                //Console.WriteLine("tt font name: " + tt + " con option : " + temp);  //
                                uniTxt = UnicodeConverter.Converter.Convert(t2, temp);
                            }
                            break;
                        }
                        else
                        {
                            uniTxt = t2;
                        }
                    }
                    catch (Exception ex)
                    {
                        Logging.logger += "UnicodeConverter.Convert() [if (tt.Contains(strarr[j]))] give Error:::: " + ex.Message + "\n";
                    }
                }

                newnodetext.InnerText = uniTxt;
                try
                {
                    root.ReplaceChild(newnodetext, LastNode); //Update combined result to Old XML file
                }
                catch (Exception ex)
                {
                    Logging.logger += "UnicodeConverter.Convert() [ root.ReplaceChild(newnodetext, LastNode)] give Error:::: " + ex.Message + "\n";
                }
            }

            //string tem = System.IO.Directory.GetCurrentDirectory();
            string tem      = saveFilePath.Substring(0, saveFilePath.LastIndexOf('\\'));
            string savename = tem + "\\finishxml.xml";

            doc.Save(savename);

            uti.SaveToDoc(savename, saveFilePath);
        }
Exemplo n.º 7
0
        public static bool Convert(string srcFile, string desFile,
                                   UnicodeConverter.Converter.ConvertOption convertOption)
        {
            bool success = false;

            string fileType = srcFile.Substring(srcFile.LastIndexOf('.'));

            try
            {
                switch (fileType)
                {
                case ".txt": TextConverter.Convert(desFile, convertOption);
                    success = true;
                    break;

                case ".sql": TextConverter.ConvertSql(desFile, convertOption);
                    success = true;
                    break;

                case ".xml": XMLConverter.ConvertSimpleXml(srcFile, desFile, convertOption);
                    success = true;
                    break;

                case ".xls": ExcelConverter.Convert(openExcel(desFile));
                    excelApp.ActiveWorkbook.Save();

                    success = true;
                    break;

                case ".xlsx": ExcelConverter.Convert(openExcel(desFile));
                    excelApp.ActiveWorkbook.Save();

                    success = true;
                    break;

                case ".doc":     //WordConverter.Convert(openWord(desFile), convertOption);
                    //Console.WriteLine("To Convert doc file as xml");
                    try
                    {
                        WordConverter.Convert(srcFile, convertOption, desFile);
                        //Logging.WriteLog();
                        openWord((Object)desFile);
                        success = true;
                    }
                    catch (Exception e)
                    {
                        Logging.logger += "Error End...0";
                        Logging.WriteLog();
                    }
                    break;

                case ".docx":     //WordConverter.Convert(openWord(desFile), convertOption);
                    //Console.WriteLine("To Convert doc file as xml");
                    try
                    {
                        WordConverter.Convert(srcFile, convertOption, desFile);
                        //Logging.WriteLog();
                        openWord((Object)desFile);
                        success = true;
                    }
                    catch (Exception e)
                    {
                        Logging.logger += "Error End...0";
                        Logging.WriteLog();
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                Logging.logger += "Error End...1";
                Logging.WriteLog();
                Console.WriteLine(ex.Message);
            }
            finally
            {
            }
            return(success);
        }
        public static void Convert(Excel.Application excelApp)
        {
            object misValue = System.Reflection.Missing.Value;

            Excel.Range    usedRange;
            Excel.Range    currentCell;
            Excel.Workbook aWorkbook = (Excel.Workbook)excelApp.ActiveWorkbook;
            //Excel.Worksheet activeWorkSheet = (Excel.Worksheet)aWorkbook.ActiveSheet;
            int sheetCount = aWorkbook.Sheets.Count;

            //System.Windows.Forms.MessageBox.Show("sheet count::" + sheetCount);

            for (int sheetNo = 1; sheetNo <= sheetCount; sheetNo++)
            {
                Excel.Worksheet currentWorkSheet;
                try
                {
                    currentWorkSheet = (Excel.Worksheet)aWorkbook.Sheets[sheetNo];
                    currentWorkSheet.Activate();
                    currentWorkSheet.Application.Cells.Activate();
                    usedRange = currentWorkSheet.UsedRange;

                    // get the total row and column count of used Range
                    int totalRows    = usedRange.Rows.Count;
                    int totalColumns = usedRange.Columns.Count;

                    for (int i = 1; i <= totalRows; i++)
                    {
                        for (int j = 1; j <= totalColumns; j++)
                        {
                            //currentWorkSheet.
                            //ExcelCtrl.AddNamedRange();
                            currentCell = ((Excel.Range)usedRange.Cells[i, j]);
                            //Console.WriteLine("detecting...0" + currentCell.Text);
                            UnicodeConverter.Converter.ConvertOption option = detectFont(currentCell);
                            //Console.WriteLine("detecting...finished   " + currentCell.Text + "   " + option);
                            if (currentCell != null && option != UnicodeConverter.Converter.ConvertOption.OTHER)
                            {
                                //Console.WriteLine("converting...0");
                                Object currentCellData = currentCell.Text;
                                if (currentCellData != null && ((string)currentCell.Text) != "")
                                {
                                    //Console.WriteLine("converting...inner not empty if");
                                    string srcTxt = (string)currentCell.Text;
                                    //Console.WriteLine("converting...getting data" + srcTxt + "   its formula:: " + currentCell.Formula.ToString());
                                    string uniTxt = UnicodeConverter.Converter.Convert(srcTxt, option);
                                    currentCell.Value2 = uniTxt + "";
                                    //Console.WriteLine("converting...finished" + uniTxt);
                                    //Console.WriteLine("converting...replaced");
                                }
                                //else
                                //{
                                //    currentCell.Value2 = "*";
                                //}
                            }
                        }
                        //Console.WriteLine("Row: " + i + " is finished converting!");
                    } // end of outer-for
                }
                catch (Exception e)
                {
                    Console.WriteLine("ExcelConverter.Convert() Error :--> " + e.Message);
                    continue;
                }
                // set "Myanmar3"to default sript name
                //Console.WriteLine("Code reach end of line!");
                usedRange.Font.Name = "Myanmar3";
            }
            //activeWorkSheet.Application.Cells.Activate();
            ((Excel.Worksheet)aWorkbook.Sheets[1]).Activate();
        }// end of Convert()
Exemplo n.º 9
0
        public static void ConvertSimpleXml(string srcFile, string desFile, UnicodeConverter.Converter.ConvertOption convertOption)
        {
            StringBuilder StrBil = new StringBuilder();

            XmlTextReader reader = new XmlTextReader(srcFile);

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:                // The node is an element.
                    StrBil.Append("<" + reader.Name);
                    while (reader.MoveToNextAttribute()) // Read the attributes.
                    {
                        StrBil.Append(" " + reader.Name + "=\"" + reader.Value + "\"");
                    }
                    StrBil.Append(">");
                    break;

                case XmlNodeType.Text:
                    //  StrBil.Append(UnicodeConverter.Converter.Convert(reader.Value, convertOption));
                    StrBil.Append(UnicodeConverter.Converter.Convert(reader.Value, convertOption));
                    break;

                case XmlNodeType.EndElement:
                    StrBil.Append("</" + reader.Name + ">" + "\r\n");
                    break;

                case XmlNodeType.Comment:
                    StrBil.Append("<!--" + reader.Value + "-->");
                    break;

                case XmlNodeType.XmlDeclaration:
                    StrBil.Append("<?" + reader.Name);
                    while (reader.MoveToNextAttribute())     // Read the attributes.
                    {
                        StrBil.Append(" " + reader.Name + "=\"" + reader.Value + "\"");
                    }
                    StrBil.Append("?>");
                    break;

                case XmlNodeType.Document: break;

                case XmlNodeType.DocumentType:
                    StrBil.Append("<!DOCTYPE" + reader.Name + "[" + reader.Value + "]");
                    break;

                case XmlNodeType.EntityReference:
                    StrBil.Append(reader.Name);
                    break;

                case XmlNodeType.CDATA:
                    StrBil.Append("<![CDATA[" + UnicodeConverter.Converter.Convert(reader.Value, convertOption) + "]]>");
                    break;

                case XmlNodeType.ProcessingInstruction:
                    StrBil.Append("<?" + reader.Name + " " + reader.Value + "?>");
                    break;
                }
            }
            reader.Close();

            StreamWriter sw = new StreamWriter(desFile);

            sw.Write(StrBil);
            sw.Close();
        }