public static void Convert(Excel.Application excelApp, UniConversion.Converter.ConvertOption option) { 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 = (Excel.Worksheet)aWorkbook.Sheets[sheetNo]; 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; //System.Windows.Forms.MessageBox.Show(totalRows + " , " + totalColumns); try { for (int i = 1; i < totalRows; i++) { for (int j = 1; j < totalColumns; j++) { currentCell = ((Excel.Range)usedRange.Cells[i, j]); if (currentCell != null) { //System.Windows.Forms.MessageBox.Show("converting....0"); if (((string)currentCell.Text) != "") { string srcTxt = (string)currentCell.Text; //Console.WriteLine("Row: " + i + " is converting:2"); string uniTxt = UniConversion.Converter.Convert(srcTxt, option); //Console.WriteLine("Row: " + i + " is converting:3"); currentCell.Value2 = uniTxt; //currentCell.Font.Name = "Myanmar3"; } //else //{ // currentCell.Value2 = "*"; //} } } //Console.WriteLine("Row: " + i + " is finished converting!"); } // end of outer-for } catch (Exception e) { Console.WriteLine("Error is:::::::" + e.Message); continue; } // set "Myanmar3"to default sript name //Console.WriteLine("Code reach end of line!"); usedRange.Font.Name = "Myanmar3"; } activeWorkSheet.Application.Cells.Activate(); }// end of Convert()
public static void Convert(string desFile, UniConversion.Converter.ConvertOption convertOption) { string desTxt = UniConversion.Converter.Convert(readTxtFile(desFile), convertOption); writeTxtFile(desTxt, desFile); openTxtFile(desFile); }
public static void Convert(string desFile, UniConversion.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); }
public static bool Convert(string srcFile, string desFile, UniConversion.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 ".xml": XMLConverter.Convert(desFile, convertOption); success = true; break; case ".xls": ExcelConverter.Convert(openExcel(desFile), convertOption); excelApp.ActiveWorkbook.Save(); success = true; break; case ".doc": WordConverter.Convert("TempXml.xml", convertOption); //wordApp.ActiveDocument.Save(); success = true; break; } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { } return(success); }
//public static void Convert(Word.Application wordApp, UniConversion.Converter.ConvertOption option) //{ //string srcTxt = wordApp.ActiveDocument.Content.Text; //string uniTxt = UniConversion.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"; // } //********************************************************** public static void Convert(string openFilePath, UniConversion.Converter.ConvertOption) { XmlDocument doc = new XmlDocument(); doc.Load(openFilePath); 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"; Console.WriteLine(ex.Message); } XmlNodeList nodes = doc.GetElementsByTagName("w:r");//Getting Nodelist from input XML file. w:r is node tag name XmlNode LastNode; XmlNode newnodetext; string uniTxt = ""; UniConversion.Converter.ConvertOption fontobj = new UniConversion.Converter.ConvertOption(); fontobj = UniConversion.Converter.ConvertOption.Amyanmar2Uni; string[] strarr = new string[7]; for (int i = 0; i < 7; i++) { strarr[i] = fontobj.ToString().Substring(0, fontobj.ToString().LastIndexOf('2')); 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; } catch (Exception ex) { tt = "Times New Roman"; Console.WriteLine(ex.Message); } for (int j = 0; j < strarr.Length; j++) { try { if (tt.Contains(strarr[j])) { UniConversion.Converter.ConvertOption temp = (UniConversion.Converter.ConvertOption)j; uniTxt = UniConversion.Converter.Convert(t2, temp); break; } else { uniTxt = t2; } } catch (Exception ex) { Console.WriteLine(ex.Message); } } newnodetext.InnerText = uniTxt; try { root.ReplaceChild(newnodetext, LastNode);//Update combined result to Old XML file } catch (Exception ex) { Console.WriteLine(ex.Message); } } string tem = System.IO.Directory.GetCurrentDirectory(); string savename = tem + "\\finishxml.xml"; doc.Save(savename); }