www.webdeveloper.com
Results 1 to 5 of 5

Thread: Javascript excel object

  1. #1
    Join Date
    Jul 2011
    Posts
    3

    Javascript excel object

    Hi,

    I have the following VBA code which I want to convert to javascript.
    this is to create a textbox shape in an excel sheet and put some text in it, and format part of the text.

    vba Code
    Sub test()

    Dim wbk1 As Excel.Workbook
    Dim sht1 As Excel.Worksheet
    Set wbk1 = Workbooks.Add
    Dim m As Shape

    Set sht1 = wbk1.Worksheets(1)

    MsgBox sht1.Name

    Set m = sht1.Shapes.AddTextbox(1, 0, 0, 100, 100)

    m.TextFrame.Characters.Text = "First Line" & Chr(10) & "Second Line"
    m.TextFrame.Characters(4, 4).Font.Bold = 1

    End Sub


    I have the following Javascript code for creating the excel workbook and put the shape in it. I cant do the rest of the code.
    Please help


    JavaScript code:
    var xls = new ActiveXObject ( "Excel.Application" );
    var newBook = xls.Workbooks.Add;
    newBook.Worksheets.Add;
    newBook.Worksheets(1).Activate;

    ws1 = newBook.Worksheets(1);
    shp1 = ws1.Shapes.Addtextbox(1,0,0,100,100);
    sh1.TextFrame.Characters.Text = "First Line" +"\n"+ "Second Line";


    The last line in the above code is not working.(it says: object does not support this property")

    please help

    Thanks in advance.

  2. #2
    Join Date
    Jul 2011
    Posts
    3
    Hi,

    I have the following VBA code which I want to convert to javascript.
    this is to create a textbox shape in an excel sheet and put some text in it, and format part of the text.

    vba Code
    Sub test()

    Dim wbk1 As Excel.Workbook
    Dim sht1 As Excel.Worksheet
    Set wbk1 = Workbooks.Add
    Dim m As Shape

    Set sht1 = wbk1.Worksheets(1)

    MsgBox sht1.Name

    Set m = sht1.Shapes.AddTextbox(1, 0, 0, 100, 100)

    m.TextFrame.Characters.Text = "First Line" & Chr(10) & "Second Line"
    m.TextFrame.Characters(4, 4).Font.Bold = 1

    End Sub


    I have the following Javascript code for creating the excel workbook and put the shape in it. I cant do the rest of the code.
    Please help


    JavaScript code:
    var xls = new ActiveXObject ( "Excel.Application" );
    var newBook = xls.Workbooks.Add;
    newBook.Worksheets.Add;
    newBook.Worksheets(1).Activate;

    ws1 = newBook.Worksheets(1);
    shp1 = ws1.Shapes.Addtextbox(1,0,0,100,100);
    shp1.TextFrame.Characters.Text = "First Line" +"\n"+ "Second Line";


    The last line in the above code is not working.(it says: object does not support this property")

    please help

    Thanks in advance.[/QUOTE]

  3. #3
    Join Date
    Jul 2011
    Posts
    3
    (there was a mistake in the last line of the code, actually it is as below.

    shp1.TextFrame.Characters.Text = "First Line" +"\n"+ "Second Line";

    still the code doesnt work in javascript.

  4. #4
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    you can build CSV files in any browser without special syntax.
    you can also make a simple array prototype to export any array as a tsv.

    generically:
    Code:
    o=[
    	{
    		"name": "fred",
    		"id": "jdffg",
    		"age": 5
    	},
    	{
    		"name": "jane",
    		"id": "cxvbv",
    		"age": 76
    	},
    	{
    		"name": "bill",
    		"id": "yhfgb",
    		"age": 32
    	},
    	{
    		"name": "john",
    		"id": "ktgfd",
    		"age": 54
    	}
    ]
    
    var cols=Object.keys(o[0]), s=cols.join("\t");
    
    o.map(function(row,rowNum){
      s+="\n";
      cols.map(function(a,i){
         s+= row[a] +"\t";
      });
    });
    
    window.open("data:text/csv;,"+escape(s));


    or,

    Code:
    sheet=[
    ["name", "gdfhj", "age"],
    ["fred", "jdffg", 5],
    ["jane", "cxvbv", 76],
    ["bill", "yhfgb", 32],
    ["john", "ktgfd", 54]
    ];
    
    window.open("data:text/csv;,"+escape(sheet.map(function(a){return a.join("\t")}).join("\n")));

  5. #5
    Join Date
    Aug 2013
    Posts
    1
    Hi, were you able to find a solution for this error??? I´m having exactly the same problem y have been unable to find a workaround.

    Thank´s in advance.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles