Tag Archive: javascript


  • Download and install VS Code.
  • Type Ctrl + Shift + P and type Install extensions.
  • Select Debugger for NWjs and click Install.
  • Type Ctrl + Shift + P and type NWjs and select NWjs Install from the dropdown menu.
  • Select File from the menu and Open Folder and choose a folder where your RMMZ project is stored.
  • Go to Run -> Add Configuration, then select NWJs from the dropdown menu.
  • Add a configuration to launch.json. launch.json should look something like this afterwards:
    {
        "version": "0.2.0",
        "configurations": [
            {
                "type": "nwjs",
                "request": "launch",
                "name": "Launch NWjs",
                "nwjsVersion": "any",
                "webRoot": "${workspaceFolder}",
                "reloadAfterAttached": true
            },
            {
                "type": "nwjs",
                "request": "attach",
                "name": "Attach to NWjs",
                "port" : 9222,
                "webRoot": "${workspaceFolder}",
                "reloadAfterAttached": true
            }
        ]
    }
    
  • Backup packages.json and then change chromium-args to the following value
    "--remote-debugging-port=9222"
    Every time you open your RMMZ project, package.json will be overwritten, so keep a copy of your file with the debugging port handy.
  • Now go to the Run and Debug tab (CTRL + SHIFT + D) and change Launch NWjs to Attach to NWjs in the upper left corner.
  • Now, start Playtest in RPG Maker MZ. Check if package.json is still correct and then press the play button next to Attach to NWjs. (In the future, you can start the debugger by pressing F5.)

Original Blog Post for RPG Maker MV: https://forums.rpgmakerweb.com/index.php?threads/debug-rmmv-plugins-with-vs-code.99980/

Export DispForm to Excel

To export an item out of a SharePoint DispForm you can use the following javascript function.

function Export()
{
	var table = $("table[class='ms-formtable']");
	var replacer = new RegExp("<BR>","g");
	var nbspReplacer = new RegExp("&nbsp;","g");		

	var xls = new ActiveXObject("Excel.Application")
	xls.visible = true
	var xlsBook = xls.Workbooks.Add
	countRow = 2;
	countColumn = 1;
	xls.columns("A").columnwidth=40;
	xls.columns("B").columnwidth=60;
	xls.columns("B").WrapText = true;
	xls.columns("A").verticalAlignment = -4160;
	xls.columns("B").verticalAlignment = -4160;
	xls.Cells( 1, 1).interior.colorindex=44;
	xls.Cells( 1, 2).interior.colorindex=44;
	xls.Cells( 1, 2).Value = "GG-Zwischenfall";
	xls.Cells( 1, 2).font.name="Arial";
  	xls.Cells( 1, 2).font.size=10;
  	xls.Cells( 1, 2).font.bold=true;
  	xls.Cells( 1, 2).borders(10).LineStyle = 1;
  	xls.Cells( 1, 2).borders(10).Weight = -4138;
        xls.Cells( 1, 2).borders(10).ColorIndex = -4105;
        xls.Cells( 1, 1).borders(7).LineStyle = 1;
  	xls.Cells( 1, 1).borders(7).Weight = -4138;
        xls.Cells( 1, 1).borders(7).ColorIndex = -4105;
        xls.Cells( 1, 2).borders(8).LineStyle = 1;
  	xls.Cells( 1, 2).borders(8).Weight = -4138;
        xls.Cells( 1, 2).borders(8).ColorIndex = -4105;
        xls.Cells( 1, 1).borders(8).LineStyle = 1;
  	xls.Cells( 1, 1).borders(8).Weight = -4138;
        xls.Cells( 1, 1).borders(8).ColorIndex = -4105;

        xlsBook.activeSheet.pageSetup.Zoom = false;
        xlsBook.activeSheet.pageSetup.FitToPagesWide = 1;
        xlsBook.activeSheet.pageSetup.FitToPagesTall = 1;
	var aufgestellt = false;
	$(table).children('TBODY').children('TR').each(function() {
  		var tr = $(this);
  		tr.find('TD').each(function() {
  			//xls.Cells( countRow, countColumn).Value = unescape($(this).text());
  			if (countColumn < 3)
  			{
  			var html = $(this).html();
  			var text = $(this).text();
  			if (html.indexOf("<DIV>") != -1 && text != "" && html.indexOf("<BR>") != -1)
  			{
  				var htmlValue = $(this).children('DIV').html();
  				var textValue = $(this).children('DIV').text();
  				//alert(textValue);
  				if (htmlValue != "" && htmlValue.indexOf("<DIV>") == -1)
  				{
  					//alert(htmlValue);
  					htmlValue = htmlValue.replace(replacer,"\n");
  					htmlValue = htmlValue.replace(nbspReplacer," ");
  					xls.Cells( countRow, countColumn).Value = unescape(htmlValue);
  				}
  				else
  				{
  					var divTextValue = "";
  					$(this).children('DIV').children('DIV').each(function() {
  						//alert ($(this).text());
  						divTextValue = divTextValue + $(this).html().replace(replacer,"\n");
   					});
   					divTextValue = divTextValue.replace(nbspReplacer," ");
  					xls.Cells( countRow, countColumn).Value = unescape(divTextValue);
  				}
  			}
  			else
  			{
  				if (html.indexOf("<DIV>") != -1 && text != "" && html.indexOf("<BR>") == -1)
  				{
  					if ($(this).children('DIV').find("DIV").length > 0)
  					{
  						var divTextValue = "";
  						$(this).children('DIV').children('DIV').each(function() {
  							//alert ($(this).text());
  							divTextValue = divTextValue + $(this).text() + "\n";
   						});
   						divTextValue = divTextValue.replace(new RegExp("\n" + '$'), '');
   						divTextValue = divTextValue.replace(nbspReplacer," ");
  						xls.Cells( countRow, countColumn).Value = unescape(divTextValue);
  					}
  					else
  					{
  						xls.Cells( countRow, countColumn).Value = unescape($(this).text());
  					}
  				}
  				else
  				{
  					xls.Cells( countRow, countColumn).Value = unescape($(this).text());
  				}
  			}
  			//xls.Cells( countRow, countColumn).Value = $(this).html();
  			if (countColumn == 1)
  			{
  				xls.Cells( countRow, countColumn).font.bold="true";
  				xls.Cells( countRow, countColumn).borders(7).LineStyle = 1;
  				xls.Cells( countRow, countColumn).borders(7).Weight = -4138;
        		        xls.Cells( countRow, countColumn).borders(7).ColorIndex = -4105;
  			}
  			else
  			{
  				xls.Cells( countRow, countColumn).interior.colorindex=19;
  				xls.Cells( countRow, countColumn).borders(10).LineStyle = 1;
  				xls.Cells( countRow, countColumn).borders(10).Weight = -4138;
        		        xls.Cells( countRow, countColumn).borders(10).ColorIndex = -4105;
  			}
  			xls.Cells( countRow, countColumn).borders(8).LineStyle = 1;
  			xls.Cells( countRow, countColumn).borders(8).Weight = -4138;
        	        xls.Cells( countRow, countColumn).borders(8).ColorIndex = 15;
  			xls.Cells( countRow, countColumn).borders(9).LineStyle = 1;
  			xls.Cells( countRow, countColumn).borders(9).Weight = -4138;
        	        xls.Cells( countRow, countColumn).borders(9).ColorIndex = 15;
  			xls.Cells( countRow, countColumn).font.name="Tahoma";
  			xls.Cells( countRow, countColumn).font.size=8;
  			}
  			countColumn++;
    	});

    countRow++;
    countColumn = 1;
	});	

	$("td[class='ms-descriptiontext']").each(function() {
		xls.Cells( countRow, 1).Value = $(this).text();
		xls.Cells( countRow, 1).font.name="Tahoma";
  		xls.Cells( countRow, 1).font.size=8;
  		xls.Cells( countRow, 2).borders(10).LineStyle = 1;
  		xls.Cells( countRow, 2).borders(10).Weight = -4138;
                xls.Cells( countRow, 2).borders(10).ColorIndex = -4105;
                xls.Cells( countRow, 1).borders(7).LineStyle = 1;
  		xls.Cells( countRow, 1).borders(7).Weight = -4138;
                xls.Cells( countRow, 1).borders(7).ColorIndex = -4105;

		countRow++;
	});
	xls.Cells( countRow, 2).borders(10).LineStyle = 1;
  	xls.Cells( countRow, 2).borders(10).Weight = -4138;
        xls.Cells( countRow, 2).borders(10).ColorIndex = -4105;
        xls.Cells( countRow, 1).borders(9).LineStyle = 1;
  	xls.Cells( countRow, 1).borders(9).Weight = -4138;
        xls.Cells( countRow, 1).borders(9).ColorIndex = -4105;
        xls.Cells( countRow, 2).borders(9).LineStyle = 1;
  	xls.Cells( countRow, 2).borders(9).Weight = -4138;
        xls.Cells( countRow, 2).borders(9).ColorIndex = -4105;
        xls.Cells( countRow, 1).borders(7).LineStyle = 1;
  	xls.Cells( countRow, 1).borders(7).Weight = -4138;
        xls.Cells( countRow, 1).borders(7).ColorIndex = -4105;
	xls.Cells( countRow-1, 1).Value = "";
	//xls.columns.autofit;
}

This javascript function can be used to export data from a SharePoint NewForm to Excel. People Picker fields and Date fields are not covered by this function.

function Export()
{
	var table = $("table[class='ms-formtable']");
	var replacer = new RegExp("<BR>","g");
	var nbspReplacer = new RegExp("&nbsp;","g");
	var divReplacer = new RegExp("<div>","g");
	var divEndReplacer = new RegExp("</div>","g");
	var divExtClassReplacer = new RegExp("<div>\n", "g");
	var fieldTitle = "";
	var fieldValue = "";	

	var xls = new ActiveXObject("Excel.Application")
	xls.visible = true
	var xlsBook = xls.Workbooks.Add
	countRow = 2;
	countColumn = 1;
	xls.columns("A").columnwidth=40;
	xls.columns("B").columnwidth=60;
	xls.columns("B").WrapText = true;
	xls.columns("A").verticalAlignment = -4160;
	xls.columns("B").verticalAlignment = -4160;
	xls.columns("B").horizontalAlignment = -4131;
	xls.Cells( 1, 1).interior.colorindex=44;
	xls.Cells( 1, 2).interior.colorindex=44;
	xls.Cells( 1, 2).Value = "GG-Zwischenfall";
	xls.Cells( 1, 2).font.name="Arial";
  	xls.Cells( 1, 2).font.size=10;
  	xls.Cells( 1, 2).font.bold=true;
  	xls.Cells( 1, 2).borders(10).LineStyle = 1;
  	xls.Cells( 1, 2).borders(10).Weight = -4138;
        xls.Cells( 1, 2).borders(10).ColorIndex = -4105;
        xls.Cells( 1, 1).borders(7).LineStyle = 1;
  	xls.Cells( 1, 1).borders(7).Weight = -4138;
        xls.Cells( 1, 1).borders(7).ColorIndex = -4105;
        xls.Cells( 1, 2).borders(8).LineStyle = 1;
  	xls.Cells( 1, 2).borders(8).Weight = -4138;
        xls.Cells( 1, 2).borders(8).ColorIndex = -4105;
        xls.Cells( 1, 1).borders(8).LineStyle = 1;
  	xls.Cells( 1, 1).borders(8).Weight = -4138;
        xls.Cells( 1, 1).borders(8).ColorIndex = -4105;
        xlsBook.activeSheet.pageSetup.Zoom = false;
        xlsBook.activeSheet.pageSetup.FitToPagesWide = 1;
        xlsBook.activeSheet.pageSetup.FitToPagesTall = 1;

	$(table).children('TBODY').children('TR').each(function() {
  		var tr = $(this);
  		tr.children('TD').each(function() {
  			if (countColumn < 3)
  			{
  			if (countColumn == 1)
  			{
  				fieldTitle = unescape($(this).text()).replace(" *","");
  				xls.Cells( countRow, countColumn).Value = unescape(fieldTitle);
  				xls.Cells( countRow, countColumn).font.bold="true";
  				xls.Cells( countRow, countColumn).borders(7).LineStyle = 1;
  				xls.Cells( countRow, countColumn).borders(7).Weight = -4138;
        		        xls.Cells( countRow, countColumn).borders(7).ColorIndex = -4105;
  			}
  			if (countColumn == 2)
  			{
  				fieldValue = $("input[title = "+fieldTitle+"]").val();
  				if (fieldValue == null)
  				{
  					fieldValue = $(this).find("input[id $= 'TextField']").val();
  				}
  				if ($(this).find("select[id$='DateHours']").length > 0 && $(this).find("select[id$='DateMinutes']").length > 0)
  				{
  					fieldValue = fieldValue + " " + $(this).find("select[id$='DateHours']").children(":selected").text() + $(this).find("select[id$='DateMinutes']").children(":selected").text();
  				}

  				if (fieldValue == null)
  				{
  					fieldValue = $(this).find("textarea").val();
  					if ($(this).find("textarea:hidden").length > 0)
  					{
  					    //alert("textarea");
  						$(this).children("SPAN").children("SPAN").children("DIV").children("IFRAME").contents().find("DIV").each(function() {
  							fieldValue = fieldValue + $(this).text() + "\n";
   						});
   						if (fieldValue != null)
   						{
   							fieldValue = fieldValue.replace(new RegExp("\n" + '$'), '');
   							fieldValue = fieldValue.replace("undefined","");
   						}
  					}

  					if (fieldValue != null && fieldValue.indexOf('<div>') != -1)
  					{
  						fieldValue = fieldValue.replace("undefined","");
  						fieldValue = unescape(fieldValue.replace(divReplacer, ""));
  						fieldValue = unescape(fieldValue.replace(divEndReplacer, ""));
  						fieldValue = unescape(fieldValue.replace(divExtClassReplacer, ""));
  						fieldValue = unescape(fieldValue.replace(nbspReplacer, ""));
  					}
  				}
  				if (fieldValue == null)
  				{
  					$(this).find('input:checkbox:checked').each(function(index) {
  						if ($(this).parent().parent().parent().next("TR").find("input[title^="+fieldTitle+"]").length > 0)
  						{
  							fieldValue = fieldValue + $(this).parent().parent().parent().next("TR").find("input").val();
  						}
  						else
  						{
  							fieldValue = fieldValue + $(this).next("label").text() + "; ";
  						}
  					});
  					if (fieldValue != null)
  					{
  						fieldValue = fieldValue.replace("undefined","");
  						fieldValue = fieldValue.replace(new RegExp("; " + '$'), '');
  						//alert(fieldValue);
  					}
  				}
  				if (fieldValue == null)
  				{
  					if ($(this).find('input:radio:checked').parent().next("label").next("select").length > 0)
  					{
  						fieldValue = $(this).find('input:radio:checked').parent().next("label").next("select").children(":selected").text();
  					}
  					else
  					//if (fieldValue == null || fieldValue == '')
  					{
  						//alert(fieldValue);
  						fieldValue = $(this).find('input:radio:checked').parent().parent().parent().next("TR").find("input").val();
  					}
  				}
  				if (fieldValue == null || fieldValue == '')
  				{
  					fieldValue = $(this).find("select").children(":selected").text();
  				}
  				if ($(this).parent().attr('id') == "idAttachmentsRow" && (fieldValue == null || fieldValue == ''))
  				{
  					fieldValue = $(this).find("TD").first().text();
  				}

  				xls.Cells( countRow, countColumn).Value = unescape(fieldValue);
  				xls.Cells( countRow, countColumn).interior.colorindex=19;
  				xls.Cells( countRow, countColumn).borders(10).LineStyle = 1;
  				xls.Cells( countRow, countColumn).borders(10).Weight = -4138;
        		        xls.Cells( countRow, countColumn).borders(10).ColorIndex = -4105;
  			}
  			xls.Cells( countRow, countColumn).borders(8).LineStyle = 1;
  			xls.Cells( countRow, countColumn).borders(8).Weight = -4138;
        	        xls.Cells( countRow, countColumn).borders(8).ColorIndex = 15;
  			xls.Cells( countRow, countColumn).borders(9).LineStyle = 1;
  			xls.Cells( countRow, countColumn).borders(9).Weight = -4138;
        	        xls.Cells( countRow, countColumn).borders(9).ColorIndex = 15;
  			xls.Cells( countRow, countColumn).font.name="Tahoma";
  			xls.Cells( countRow, countColumn).font.size=8;
  			}
  			countColumn++;
    	});

    countRow++;
    countColumn = 1;
	});	

	$("td[class='ms-descriptiontext']").each(function() {
		xls.Cells( countRow, 1).Value = $(this).text();
		xls.Cells( countRow, 1).font.name="Tahoma";
  		xls.Cells( countRow, 1).font.size=8;
  		xls.Cells( countRow, 2).borders(10).LineStyle = 1;
  		xls.Cells( countRow, 2).borders(10).Weight = -4138;
                xls.Cells( countRow, 2).borders(10).ColorIndex = -4105;
                xls.Cells( countRow, 1).borders(7).LineStyle = 1;
  		xls.Cells( countRow, 1).borders(7).Weight = -4138;
                xls.Cells( countRow, 1).borders(7).ColorIndex = -4105;

		countRow++;
	});
	xls.Cells( countRow, 2).borders(10).LineStyle = 1;
  	xls.Cells( countRow, 2).borders(10).Weight = -4138;
        xls.Cells( countRow, 2).borders(10).ColorIndex = -4105;
        xls.Cells( countRow, 1).borders(9).LineStyle = 1;
  	xls.Cells( countRow, 1).borders(9).Weight = -4138;
        xls.Cells( countRow, 1).borders(9).ColorIndex = -4105;
        xls.Cells( countRow, 2).borders(9).LineStyle = 1;
  	xls.Cells( countRow, 2).borders(9).Weight = -4138;
        xls.Cells( countRow, 2).borders(9).ColorIndex = -4105;
        xls.Cells( countRow, 1).borders(7).LineStyle = 1;
  	xls.Cells( countRow, 1).borders(7).Weight = -4138;
        xls.Cells( countRow, 1).borders(7).ColorIndex = -4105;
	xls.Cells( countRow-1, 1).Value = "";
	//xls.columns.autofit;
}