Solved

jscript ActiveX excel.application programming problem

Posted on 2004-09-11
3
1,596 Views
Last Modified: 2009-07-29
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;
      xlSheet.Cells(3,1).value = "MODIFING THE LAYOUT OF THIS SPREADSHEET MAY CAUSE IMPORT ERRORS";
      
      // 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;
      xlSheet.Columns.AutoFit();
      xlApp = null;
      objExcelXML = "";
      return(0);
}


Any clues?
0
Comment
Question by:dtkn
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
davidlars99 earned 500 total points
ID: 12035526
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..?
0
 
LVL 1

Author Comment

by:dtkn
ID: 12036010
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!
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 12036660
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...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question