home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / software / pelne / optionp / wsh.cab / excel.js < prev    next >
Text File  |  1997-09-28  |  3KB  |  102 lines

  1. // Windows Script Host Sample Script
  2. //
  3. // ------------------------------------------------------------------------
  4. //               Copyright (C) 1996 Microsoft Corporation
  5. //
  6. // You have a royalty-free right to use, modify, reproduce and distribute
  7. // the Sample Application Files (and/or any modified version) in any way
  8. // you find useful, provided that you agree that Microsoft has no warranty,
  9. // obligations or liability for any Sample Application Files.
  10. // ------------------------------------------------------------------------
  11.  
  12. // This sample will display Windows Scripting Host properties in Excel.
  13.  
  14.  
  15. var vbOKCancel = 1;
  16. var vbInformation = 64;
  17. var vbCancel = 2;
  18.  
  19. var L_Welcome_MsgBox_Message_Text    = "This script will display Windows Scripting Host properties in Excel.";
  20. var L_Welcome_MsgBox_Title_Text      = "Windows Scripting Host Sample";
  21. Welcome();
  22.     
  23.  
  24. //////////////////////////////////////////////////////////////////////////////////
  25. //
  26. // Excel Sample
  27. //
  28. var objXL = WScript.CreateObject("Excel.Application");
  29.  
  30. objXL.Visible = true;
  31.  
  32. objXL.WorkBooks.Add;
  33.  
  34. objXL.Columns(1).ColumnWidth = 20;
  35. objXL.Columns(2).ColumnWidth = 30;
  36. objXL.Columns(3).ColumnWidth = 40;
  37.  
  38. objXL.Cells(1, 1).Value = "Property Name";
  39. objXL.Cells(1, 2).Value = "Value";
  40. objXL.Cells(1, 3).Value = "Description";
  41.  
  42. objXL.Range("A1:C1").Select;
  43. objXL.Selection.Font.Bold = true;
  44. objXL.Selection.Interior.ColorIndex = 1;
  45. objXL.Selection.Interior.Pattern = 1; //xlSolid
  46. objXL.Selection.Font.ColorIndex = 2;
  47.  
  48. objXL.Columns("B:B").Select;
  49. objXL.Selection.HorizontalAlignment = -4131; // xlLeft
  50.  
  51. var intIndex = 2;
  52.  
  53. function Show(strName, strValue, strDesc) {
  54.     objXL.Cells(intIndex, 1).Value = strName;
  55.     objXL.Cells(intIndex, 2).Value = strValue;
  56.     objXL.Cells(intIndex, 3).Value = strDesc;
  57.     intIndex++;
  58.     objXL.Cells(intIndex, 1).Select;
  59. }
  60.  
  61. //
  62. // Show WScript properties
  63. //
  64. Show("Name",           WScript.Name,           "Application Friendly Name");
  65. Show("Version",        WScript.Version,        "Application Version");
  66. Show("FullName",       WScript.FullName,       "Application Context: Fully Qualified Name");
  67. Show("Path",           WScript.Path,           "Application Context: Path Only");
  68. Show("Interactive",    WScript.Interactive,    "State of Interactive Mode");
  69.  
  70.  
  71. //
  72. // Show command line arguments.
  73. //
  74. var colArgs = WScript.Arguments
  75. Show("Arguments.Count", colArgs.length, "Number of command line arguments");
  76.  
  77. for (i = 0; i < colArgs.length; i++) {
  78.     objXL.Cells(intIndex, 1).Value = "Arguments(" + i + ")";
  79.     objXL.Cells(intIndex, 2).Value = colArgs(i);
  80.     intIndex++;
  81.     objXL.Cells(intIndex, 1).Select;
  82. }
  83.  
  84.  
  85. //////////////////////////////////////////////////////////////////////////////////
  86. //
  87. // Welcome
  88. //
  89. function Welcome() {
  90.     var WSHShell = WScript.CreateObject("WScript.Shell");
  91.     var intDoIt;
  92.  
  93.     intDoIt =  WSHShell.Popup(L_Welcome_MsgBox_Message_Text,
  94.                               0,
  95.                               L_Welcome_MsgBox_Title_Text,
  96.                               vbOKCancel + vbInformation );
  97.     if (intDoIt == vbCancel) {
  98.         WScript.Quit();
  99.     }
  100. }
  101.  
  102.