Solved

jscript ActiveX excel.application programming problem

Posted on 2004-09-11
3
1,591 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
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'…
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…

861 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now