//-----------------------------
function getCommandline()
{
var cmln = RolandRaue.commandLine.replace(/ /g,"").split("-");
if( cmln.length == 4 )
{
locations.infile = cmln[1].replace(/\\/g,"/");
locations.startSheet = cmln[2];
locations.outfile1 = cmln[3].replace(/\\/g,"/");
}
};
//------------------------------------------------------
//-- leere Elemente löschen
//------------------------------------------------------
function deleteEmpty( infile )
{
var i = 0;
var out = [];
for( i = 0; i < infile.length; i++ )
{
if( infile[ i ] ) { out.push( infile[i] ); }
}
out.pop();
return out;
};
function deleteEmpty( anzahl )
{
var i = 0;
var out_anz = [];
for( i = 0; i < anzahl.length; i++ )
{
if( anzahl[ i ] ) { out_anz.push( anzahl[i] ); }
}
out_anz.pop();
return out_anz;
};
//-----------------------------
function init()
{
var infile, list, out, anzahl;
getCommandline();
msg( "<br>--- Excel Datei laden: ---<br>" );
infile = loadExcelFile( locations.infile, locations.startSheet );
infile = deleteEmpty( infile );
infile = convertInfile( infile );
anzahl = loadExcelFile( locations.infile, locations.startSheet );
anzahl = deleteEmpty( anzahl );
anzahl = convertAnzahl( anzahl );
msg( "<br>--- Dateien finden: ---<br>" );
list = getSortedList( [ locations.posA, locations.posB, locations.posC ] );
list = findLast( list );
out = checkIfInFileList( list, infile, anzahl );
if( Eingabewerte.STL_vorhanden == "Ja" || Eingabewerte.STL_Tür_Links_vorhanden == "Ja" || Eingabewerte.STL_Tür_Rechts_vorhanden == "Ja" || Eingabewerte.STL_Tür_LinksRechts_vorhanden == "Ja" )
{
document.getElementById( "STL_Meldungen_Überschreiben" ).style.display = "inline";
document.getElementById( "STL_Meldungen_Alt_Text" ).style.display = "inline";
document.getElementById( "STL_Meldungen_Alt_Text" ).disabled = true;
document.getElementById( "Überschreiben_Alt_Text" ).disabled = true;
document.getElementById( "Alt_Text" ).disabled = true;
}
save( out );
return;
}
//------------------------------------------
function convertInfile( infile )
{
var i = 0; var last = ""; zaehler = 1;
for( i = 0; i < infile.length; i++ )
{
if( infile[ i ] )
{
if( last == infile[ i ] ) zaehler++; else zaehler = 1;
last = infile[ i ].substr( 0, 14 );
infile[ i ] = convertFileNameToObject( infile[ i ] );
infile[ i ].zaehler = zaehler;
msg( "infile: " + last + " / " + i + " " + infile[ i ] + "<br>" )
}
}
return infile;
};
function convertFileNameToObject( fn )
{
fn = fn.replace( /-/g, "_" );
fn = fn.substr( 0, 14 );
out = fn;
return out;
}
//------------------------------------------
function convertAnzahl( anzahl )
{
var i = 0; var last = "";
for( i = 0; i < anzahl.length; i++ )
{
if( anzahl[ i ] )
{
last = anzahl[ i ].substr( 0, 14 );
anzahl[ i ] = convertAnzahlToObject( anzahl[ i ] );
if( anzahl[ i ] == 1 ) { anzahl[ i ] = "" };
msg( "Anzahl: " + last + " ( " + anzahl[ i ] + " )<br>" )
}
}
return anzahl;
};
function convertAnzahlToObject( anz )
{
anz = anz.substr( 17, 3 );
out_anz = anz;
return out_anz;
};
//------------------------------------------
//-- Exceldatei laden, Array zurückliefern
//------------------------------------------
function loadExcelFile( fileName, sheetName )
{
var x, y;
var currentRange;
var currentSheet;
var excelApp = new ActiveXObject("Excel.Application");
var wbin;
var out = new Array();
try { wbin = excelApp.Workbooks.Open( fileName ); }
catch(e)
{
STL_Meldungen_Fehler( "(!) konnte folgende Datei nicht öffnen: '" + fileName + "' (!)" );
return [];
}
currentSheet = get_sheet_by_name( wbin, sheetName );
if( currentSheet )
{
currentRange = currentSheet.UsedRange;
for ( y = locations.startRow; y < currentRange.Rows.Count; y++ )
{
out.push( currentRange.Cells( y + 1, locations.startCol1 ).Text + currentRange.Cells( y + 1, locations.startCol1_1 ).Text );
}
for ( y = locations.startRow; y < currentRange.Rows.Count; y++ )
{
out.push( currentRange.Cells( y + 1, locations.startCol2 ).Text + currentRange.Cells( y + 1, locations.startCol2_2 ).Text );
}
}
wbin.Close();
excelApp.Quit();
return out;
function get_sheet_by_name( wb, name )
{
var i;
for( i = 1; i < wb.Sheets.Count + 1; i++ )
{
if( wb.Sheets( i ).name == name )
{
return wb.Sheets( i );
}
}
STL_Meldungen_Fehler( "(!) Tabelle '" + name + "' nicht gefunden (!)" );
return false;
}
}
//-----------------------------
function checkIfInFileList( list, infile, anzahl )
{
var i,temp;
var out = [];
for( i = 0; i < infile.length && anzahl.length; i++ ) { out = out.concat( findInList( infile[i] ) ); }
return out;
function findInList( s )
{
var i = 0;
var out = [];
for( i = 0; i < list.length; i++ )
{
if( s == list[i].n.join("_").substr( 0, 14 ) ) out.push( list[i] );
}
if( out.length == 0 ) return [s];
return out;
}
};
//-----------------------------
function save( list )
{
var out = [];
for( var i = 0; i < list.length; i++ )
{
if( list[i].n )
{
out.push( list[i].n.join("") + ".nc" );
msg( i + " " + list[i].n + " - " + list[i].p + "<br>" );
}
else
{
out.push( "! datei nicht gefunden: '" + list[i] + "'" );
msg( i + " " + "! datei nicht gefunden '" + list[i] + "' !<br>" );
}
}
document.getElementById( "STL_Meldungen_Überschreiben" ).innerHTML = '<p class="STL_Meldungen_Überschreiben">Wollen Sie die Stückliste Überschreiben? <input type="button" value="Bestätigen" class="STL_Meldungen_Button" onclick="saveFile( locations.workFolder1 + locations.outfile1, out.join("") );"></input> <input type="button" value="Abbrechen" class="STL_Meldungen_Button" onclick="Überschreiben_Abbrechen()"></input>';
//saveFile( locations.workFolder1 + locations.outfile1, out.join("\r\n") );
};
//-----------------------------
function getSortedList( locs )
{
var out = new Array();
var temp, i, k;
for( i = 0; i < locs.length; i++ )
{
temp = getFiles( locs[i], 5 )[1];
for( k = 0; k < temp.length; k++ )
{
temp[k] = { p:temp[k].path, n:temp[k].name };
temp[k].p = temp[k].p.replace(/\\/g,"/");
temp[k].p = temp[k].p.substr( 0, temp[k].p.lastIndexOf("/") );
temp[k].n = temp[k].n.split(".")[0];
temp[k].n = [ temp[k].n.substr( 0, 14 ), temp[k].n.substr( 14 ) ];
out.push( temp[k] );
}
}
out.sort( sort );
out = findLast( out );
return out;
//__
function sort( a, b )
{
var i;
a = a.n;
b = b.n;
for( i = 0; i < a.length; i++ )
{
if( !b[i] ) return 1;
if( a[i].length > b[i].length ) return 1;
if( a[i].length < b[i].length ) return -1;
if( a[i] > b[i] ) return 1;
if( a[i] < b[i] ) return -1;
}
return 0;
};
};
//__
function findLast( arr )
{
var i = 0;
var out = new Array();
var temp = [];
var current000, last000;
var currentX, lastX;
var current00x, last00x;
for( i = 0; i < arr.length; i++ )
{
current000 = arr[i].n[0];
current00x = arr[i].n[1].split("_")[1];
currentX = arr[i].n[1].split("_")[0];
if( last000 != current000 )
{
out = out.concat( temp );
temp = [];
}
if( i > 0 && lastX != currentX ) { temp = []; }
temp.push( arr[ i ] );
last000 = current000;
lastX = currentX;
last00x = current00x;
}
return out;
};
//-----------------------------------------------------------------------
function saveFile(FileName,str)
{
var fso, folder, file, foldername;
//____
function getfoldername(s) { s = s.replace(/\\/g,"/"); s = s.substr( 0, s.lastIndexOf("/") ); return s; }
fso = new ActiveXObject("Scripting.Filesystemobject");
foldername = getfoldername(FileName);
if(fso.FolderExists(foldername))
{
folder = fso.Getfolder(foldername);
if(folder.attributes!=16&&folder.attributes!=48)
{
STL_Meldungen_Fehler("[savefile] kann auf Verzeichnis nicht zugreifen ---><b>" + foldername + "</b> (att:" + folder.attributes + ")");
return false;
}
if(fso.FileExists(FileName))
{
file = fso.GetFile(FileName);
if(file.attributes!=0&&file.attributes!=32)
{
STL_Meldungen_Fehler("[savefile] kann auf Datei nicht zugreifen ---><b>" + FileName + "</b> (att:" + file.attributes + ")");
return false;
}
}
file = fso.OpenTextFile(FileName, 2, true);
file.write(str);
file.close();
}
else
{
STL_Meldungen_Fehler("Verzeichnis nicht gefunden! ---><b>" + foldername + "</b>");
}
}
//-----------------------------------------------------------------------------------
//-- returns an array: [ array of folder objects, array of file objects ]
//-- filter:
//-- n = 0000 (0): all folders and subfolders and all files
//-- n = 0001 (1): no folders
//-- n = 0010 (2): no files
//-- n = 0100 (4): no subfolders
//-- ext = extension as STRING
//-- part = member as STRING, eg. "name"
//-----------------------------------------------------------------------------------
function getFiles( startfolder, n , ext, part )
{
if( !n ) n = 0;
var fso = new ActiveXObject("Scripting.FileSystemObject");
var folders = new Array();
var files = new Array();
if( !fso.FolderExists( startfolder ) )
{
STL_Meldungen_Fehler("(!) Folder " + startfolder + " not found!", true );
return [ [],[] ];
}
getNext( startfolder );
return [ folders, files ];
function getNext( fld )
{
var folderObj = fso.getFolder( fld );
var filesEn, foldersEn;
var tmp = "";
if( (n & 2) == 0 )
{
filesEn = new Enumerator( folderObj.Files );
for (; !filesEn.atEnd(); filesEn.moveNext())
{
tmp = filesEn.item().name;
if( typeof(ext) == 'undefined' || tmp.substr( tmp.length - ext.length, ext.length ).toLowerCase() == ext.toLowerCase() )
{
if( typeof(part) != 'undefined' && filesEn.item()[part] != 'undefined' )
files.push( filesEn.item()[part] )
else
files.push( filesEn.item() );
}
}
}
if( (n & 1) == 0 )
{
folders.push( folderObj );
foldersEn = new Enumerator( folderObj.SubFolders );
if( (n & 4) == 0 )
{
for (; !foldersEn.atEnd(); foldersEn.moveNext()) getNext( foldersEn.item().path );
}
}
}
}
//-----------------------------
function msg( s ) { document.getElementById("msgs").innerHTML += s; };
function STL_Meldungen_Fehler( Fehler )
{
document.getElementById("STL_Meldungen_Fehlerausgabe").style.display = "inline";
document.getElementById("STL_Meldungen_Fehler").innerHTML += Fehler + '<br>';
};
romero: Weiter Spalte anhängen
Beitrag lesen
Weiter Spalte anhängen
romero
- javascript
0 romero0 Romero0 Romero
0 Romero