1414using DotNetSiemensPLCToolBoxLibrary . DataTypes . Projectfolders ;
1515using DotNetSiemensPLCToolBoxLibrary . General ;
1616using DotNetSiemensPLCToolBoxLibrary . Projectfiles ;
17+ using ICSharpCode . SharpZipLib . Core ;
18+ using OfficeOpenXml ;
19+ using OfficeOpenXml . FormulaParsing . Excel . Functions . Text ;
1720using TiaGitHandler . Properties ;
1821using Application = System . Windows . Application ;
1922using MessageBox = System . Windows . Forms . MessageBox ;
@@ -211,6 +214,26 @@ static void Main(string[] args)
211214 ParseFolder ( prj . ProjectStructure , exportPath , skippedBlocksList ) ;
212215 prj . ExportTextlists ( prj . ProjectStructure , exportPath ) ;
213216
217+ var xlsxFiles = Directory . GetFiles ( exportPath , "*.xlsx" , SearchOption . AllDirectories ) ;
218+ foreach ( var xlsxFile in xlsxFiles . Where ( x => x . Contains ( "plcalarmtextlistgroup" ) ) )
219+ {
220+ var fileInfo = new FileInfo ( xlsxFile ) ;
221+ using ( var package = new ExcelPackage ( fileInfo ) )
222+ {
223+ var worksheet1 = package . Workbook . Worksheets [ 1 ] ;
224+ var textlistType = worksheet1 . Cells [ "B2" ] . Text ; // textlist type - decimal, binary, bit
225+
226+ string targetFile = Path . Combine (
227+ Path . GetDirectoryName ( xlsxFile ) ,
228+ $ "{ Path . GetFileNameWithoutExtension ( xlsxFile ) } _{ textlistType } .csv"
229+ ) ;
230+
231+ ConvertPlcAlarmTextListXlsxToCsv ( xlsxFile , targetFile , textlistType ) ;
232+ }
233+
234+ File . Delete ( xlsxFile ) ;
235+ }
236+
214237 Console . WriteLine ( ) ;
215238 Console . WriteLine ( ) ;
216239 Console . ForegroundColor = ConsoleColor . Red ;
@@ -221,6 +244,43 @@ static void Main(string[] args)
221244 Console . ReadKey ( ) ;
222245 }
223246
247+ public static void ConvertPlcAlarmTextListXlsxToCsv ( string sourceFile , string targetFile , string textlistType )
248+ {
249+ var fileInfo = new FileInfo ( sourceFile ) ;
250+ using ( var package = new ExcelPackage ( fileInfo ) )
251+ {
252+ var worksheet = package . Workbook . Worksheets [ 2 ] ;
253+
254+ var maxColumnNumber = worksheet . Dimension . End . Column ;
255+ var totalRowCount = worksheet . Dimension . End . Row ;
256+
257+ using ( var writer = new StreamWriter ( targetFile , false , Encoding . UTF8 ) )
258+ {
259+ for ( int row = 1 ; row <= totalRowCount ; row ++ )
260+ {
261+ var currentRow = new List < string > ( maxColumnNumber ) ;
262+
263+ for ( int col = 1 ; col <= maxColumnNumber ; col ++ )
264+ {
265+ var cellValue = worksheet . Cells [ row , col ] . Text ;
266+
267+ // double quotation marks (") -> ("")
268+ if ( cellValue . Contains ( "\" " ) )
269+ cellValue = cellValue . Replace ( "\" " , "\" \" " ) ;
270+
271+ // Add quotation marks if cell contains commas or quotation marks
272+ if ( cellValue . Contains ( "," ) || cellValue . Contains ( "\" " ) )
273+ cellValue = $ "\" { cellValue } \" ";
274+
275+ currentRow . Add ( cellValue ) ;
276+ }
277+
278+ writer . WriteLine ( string . Join ( ";" , currentRow ) ) ;
279+ }
280+ }
281+ }
282+ }
283+
224284 private class EncodingStringWriter : StringWriter
225285 {
226286 private readonly Encoding _encoding ;
@@ -340,6 +400,7 @@ private static void ParseFolder(ProjectFolder folder, string dir, List<string> s
340400 ns . AddNamespace ( "smns2" , "http://www.siemens.com/automation/Openness/SW/Interface/v3" ) ;
341401 ns . AddNamespace ( "smns3" , "http://www.siemens.com/automation/Openness/SW/NetworkSource/StatementList/v3" ) ;
342402 ns . AddNamespace ( "smns4" , "http://www.siemens.com/automation/Openness/SW/NetworkSource/StructuredText/v2" ) ;
403+ ns . AddNamespace ( "smns5" , "http://www.siemens.com/automation/Openness/SW/NetworkSource/StructuredText/v4" ) ;
343404
344405 try
345406 {
@@ -479,6 +540,18 @@ private static void ParseFolder(ProjectFolder folder, string dir, List<string> s
479540 {
480541 }
481542
543+ try
544+ {
545+ var nodes = xmlDoc . SelectNodes ( "//smns5:DateAttribute[@Name='ParameterModifiedTS']" , ns ) ;
546+ foreach ( var node in nodes . Cast < XmlNode > ( ) )
547+ {
548+ node . ParentNode . RemoveChild ( node ) ;
549+ }
550+ }
551+ catch
552+ {
553+ }
554+
482555 //try
483556 //{
484557 // var nodes = xmlDoc.SelectNodes("//smns:Address[@Area='None' and @Informative='true']", ns);
0 commit comments