jscript ActiveX excel.application programming problem

I am creating an Excel spreadsheet for my users based on screen parameters. I basically have a screen that is created from XML and XSLT. When the user clicks a button they get an xls file listing all fields on the screen. This is being used to allow users to create import templates for the screen....fill in the template with as many new entries as they wish, then import the template instead of having to go into the screen perhaps 1000 times to enter 1000 entries. Lets not get caught up int the semantics of reasoning for doing this here though.

What i need is a way to format all the cells in the worksheet to be of type text. For instance, if you were in Excel, and highlighted the whole document, then went to Format->Cells...-> then chose the 'Text' option, it would accomplish the same thing. Currently, this is exactly what the user has to do in order to get all the data correct. I would like to automate this process for them.

Here is the basic code for the creation of the template.....

function Create_Import_Template() {
      var wrkNodes, i, sLabel, sReq, sLocked, sDataType, x;
      var xlApp = new ActiveXObject('Excel.Application');
      xlApp.Visible = true;
      xlApp.UserControl = true;
      var xlBook = xlApp.Workbooks.Add();
      var xlSheet = xlBook.Worksheets("Sheet1");
      xlSheet.Cells(1,1).value = gScreenTitle;
      xlSheet.Cells(1,1).Font.Bold = true;
      xlSheet.Cells(1,2).value = gScreenGID;
      // Export the Screen Definition to the Spreadsheet
      var objExcelXML = new ActiveXObject("MSXML2.DOMDocument.3.0");
      objExcelXML.validateOnParse = true;
      objExcelXML.async = false;
      objExcelXML.load(gTempPath + "\\Screen" + gScreenGID + ".xml");
      wrkNodes = objExcelXML.selectNodes("/DEF/DET");
      x = 1;
      for (i=0;i<wrkNodes.length;i++) {
            sDataType = wrkNodes(i).attributes.getNamedItem("Data_Type").value;
                                // code missing to place data in fields

      xlSheet.Cells(1,3).value = x;
      xlApp = null;
      objExcelXML = "";

Any clues?
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

davidlars99Connect With a Mentor Commented:
the trick here is that, excel itself can help you more than any experts here in your sutuation... just record macro and do what you want to do then see the code what it has recorded and there's your answer...
do you know how to record macros..?
dtknAuthor Commented:
Excellent answer Davidlars. I like that you didnt just give me a single answer, yet pointed me in the direction to so much more. Thanks. You get the points.....probably the easiest points you have ever recieved too!
glad I could help... BTW, I love VBA inside excel, but I have not seen it for two years though. You can do amazing things from javascript, ones like creating advanced charts and importing them as JPG into your web apps and lot lot more...
All Courses

From novice to tech pro — start learning today.