Solved

jscript ActiveX excel.application programming problem

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

771 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

8 Experts available now in Live!

Get 1:1 Help Now