Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

jscript ActiveX excel.application programming problem

Posted on 2004-09-11
3
Medium Priority
?
1,603 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
davidlars99 earned 2000 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

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…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

721 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