//[Start] public void Export_Txt_Fehlworte() { //======================================================================= // Dialogabfrage const string message = "Prüfung von fehlenden Übersetzungen durchführen?"; const string caption = "Export Fehlworteliste"; var result = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.No) { return; } //======================================================================= // aktuelles Projektpfad ermitteln string sProject = Get_Project(); //sProject = sProject.Replace("File-2", "K-ELT-01"); if (sProject == "") { MessageBox.Show("Projekt auswählen !"); return; } //MessageBox.Show(sProject); // Projektname ermitteln string strProjectname = Get_Name(sProject); //======================================================================= //eingestellte Projektsprache EPLAN ermitteln string strDisplayLanguage = null; ActionCallingContext ACCDisplay = new ActionCallingContext(); new CommandLineInterpreter().Execute("GetDisplayLanguage", ACCDisplay); ACCDisplay.GetParameter("value", ref strDisplayLanguage); //MessageBox.Show("Language : " + strDisplayLanguage); //======================================================================= //Fehlworteliste erzeugen : Eplan.EplApi.ApplicationFramework.ActionCallingContext acctranslate = new Eplan.EplApi.ApplicationFramework.ActionCallingContext(); Eplan.EplApi.ApplicationFramework.CommandLineInterpreter CLItranslate = new Eplan.EplApi.ApplicationFramework.CommandLineInterpreter(); Eplan.EplApi.Base.Progress progress = new Eplan.EplApi.Base.Progress("SimpleProgress"); progress.BeginPart(100, ""); progress.SetAllowCancel(true); string MisTranslateFile = @"c:\TEMP\EPLAN\EPLAN_Fehlworteliste_" + strProjectname + "_" + strDisplayLanguage + ".txt"; acctranslate.AddParameter("TYPE", "EXPORTMISSINGTRANSLATIONS"); acctranslate.AddParameter("LANGUAGE", strDisplayLanguage); acctranslate.AddParameter("EXPORTFILE", MisTranslateFile); acctranslate.AddParameter("CONVERTER", "XTrLanguageDbXml2TabConverterImpl"); bool sRet = CLItranslate.Execute("translate", acctranslate); if (!sRet) { MessageBox.Show("Fehler bei Export fehlende Übersetzungen!"); return; } // MessageBox.Show("Fehlende Übersetzungen exportiert in : " + MisTranslateFile); //================================================================= //Fehlworteliste lesen und Zeilenanzahl ermitteln : int counter = 0; string line; if (File.Exists(MisTranslateFile)) { using (StreamReader countReader = new StreamReader(MisTranslateFile)) { while (countReader.ReadLine() != null) { counter++; } } // MessageBox.Show("Zeilenanzahl in " + MisTranslateFile + " : " + counter); if (counter > 1) //================================================================= //Fehlworteliste öffnen falls Zeilenanzahl > 1 : { // MessageBox.Show("Fehlende Übersetzungen gefunden !"); // Open the txt file with missing translation System.Diagnostics.Process.Start("notepad.exe", MisTranslateFile); } } progress.EndPart(true); return; }
/// <summary> /// Считывание описания. /// </summary> public int LoadDescription(out string errStr, string projectName, bool loadFromLua) { errStr = ""; Logs.Clear(); EProjectManager.GetInstance().ProjectDataIsLoaded = false; string LuaStr; int res = 0; var oProgress = new Eplan.EplApi.Base.Progress("EnhancedProgress"); oProgress.SetAllowCancel(false); oProgress.SetTitle("Считывание данных проекта"); try { oProgress.BeginPart(15, "Считывание IO"); projectConfiguration.ReadIO(); oProgress.EndPart(); oProgress.BeginPart(15, "Считывание устройств"); if (projectConfiguration.DevicesIsRead == true) { projectConfiguration.SynchronizeDevices(); } else { projectConfiguration.ReadDevices(); } oProgress.EndPart(); oProgress.BeginPart(25, "Считывание привязки устройств"); projectConfiguration.ReadBinding(); oProgress.EndPart(); if (loadFromLua) { EncodingDetector.MainFilesEncoding = null; oProgress.BeginPart(15, "Считывание технологических " + "объектов"); res = LoadDescriptionFromFile(out LuaStr, out errStr, projectName, $"\\{ProjectDescriptionSaver.MainTechObjectsFileName}"); techObjectManager.LoadDescription(LuaStr, projectName); errStr = ""; LuaStr = ""; res = LoadDescriptionFromFile(out LuaStr, out errStr, projectName, $"\\{ProjectDescriptionSaver.MainRestrictionsFileName}"); techObjectManager.LoadRestriction(LuaStr); oProgress.EndPart(); } oProgress.BeginPart(15, "Проверка данных"); projectConfiguration.Check(); oProgress.EndPart(); oProgress.BeginPart(15, "Расчет IO-Link"); IOManager.CalculateIOLinkAdresses(); oProgress.EndPart(true); EProjectManager.GetInstance().ProjectDataIsLoaded = true; } catch (System.Exception ex) { MessageBox.Show(ex.Message); oProgress.EndPart(true); EProjectManager.GetInstance().ProjectDataIsLoaded = false; } return(res); }
public static void Execute(List <EplanLabellingDocumentPageLine> listOfLines, string xlsFileName, Eplan.EplApi.Base.Progress progress) { markType = new List <string>() { "ПуГВнг(А)-LS 1х1", "ПуГВнг(А)-LS 1х1,5", "ПуГВнг(А)-LS 1х2,5", "ПуГВнг(А)-LS 1х2,5 Ж-З", "ПуГВнг(А)-LS 1х4", "ПуГВнг(А)-LS 1х4 Ж-З", "" }; int sectionCount = 2; foreach (var mark in markType) { markTypeRow[mark] = 1; } Application xlApp = new Application(); sheetArray = new string[listOfLines.Count * 2, markType.Count * 2]; for (int i = 0; i < markType.Count; i++) { sheetArray[0, i * 2] = markType[i]; } try { if (xlApp == null) { DoWireMarking.DoWireMarking.MassageHandler("Excel is not properly installed!!"); return; } xlWorkBook = xlApp.Workbooks.Add(misValue); // Sheet count int sheetNumber = 1; xlWorkSheet = (Worksheet)xlWorkBook.Worksheets.get_Item(sheetNumber); for (int j = 1; j <= sectionCount; j++) { rowNumber = 1; for (int i = 0; i < listOfLines.Count; i++) { boxName = listOfLines[i].Label?.Property[1]?.PropertyValue; if (boxName.Substring(0, 4) == "ИВЕЖ") { progress.BeginPart(20.0 / listOfLines.Count, "Writing : " + boxName + " секция " + j); // Control new sheet creation sheetNumber = ManageSheets(listOfLines, sheetNumber, boxName, i, j); // Select column for each type of mark SelectMarkType(listOfLines, ref columnNumber, ref tmpMarkType, ref rowNumber, i); // Write marking name into arrays WriteDataInCells(sheetArray, listOfLines, columnNumber, rowNumber, i, j, j == 1 ? 2 : 1); rowNumber += 2; progress.EndPart(); if (progress.Canceled()) { progress.EndPart(true); i = listOfLines.Count; } } else if (j == 1) { progress.BeginPart(20.0 / listOfLines.Count, "Writing : " + boxName + " секция " + j); // Control new sheet creation sheetNumber = ManageSheets(listOfLines, sheetNumber, boxName, i, j); // Select column for each type of mark SelectMarkType(listOfLines, ref columnNumber, ref tmpMarkType, ref rowNumber, i); // Write marking name into arrays CableDataInCells(sheetArray, listOfLines, columnNumber, rowNumber, i, j, j == 1 ? 2 : 1); rowNumber += 2; progress.EndPart(); if (progress.Canceled()) { progress.EndPart(true); i = listOfLines.Count; } } } } // Write array on sheet WriteArray <string>(xlWorkSheet, 1, 1, sheetArray); xlWorkBook.SaveAs(xlsFileName, XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, XlSaveAsAccessMode.xlExclusive, XlSaveConflictResolution.xlLocalSessionChanges, misValue, misValue, misValue, misValue); Debug.WriteLine($"Excel file created , you can find it in: \"{xlsFileName}\""); } catch (Exception ex) { DoWireMarking.DoWireMarking.ErrorHandler("ExportToExcel" + "\nlistOfLines.Count " + listOfLines.Count + "\nrowNumber " + rowNumber + "\ncolumnNumber " + columnNumber + "\nboxName " + boxName, ex); return; } finally { xlWorkBook?.Close(true, misValue, misValue); xlApp?.Quit(); xlsMainSheetCounter = 1; Marshal.ReleaseComObject(xlWorkSheet); Marshal.ReleaseComObject(xlWorkBook); Marshal.ReleaseComObject(xlApp); } }