有没有办法将以下VBScript更改为javascript?

时间:2021-01-21 07:31:57

I'm attempting to convert some VBScript to javascript, but I doubt it's possible because it seems to be specific to MS apps and code. I'd like help with either of the two possible outcomes: a) actually converting the code to javascript, or b) demonstrating that converting it to javascript is currently not possible.

我试图将一些VBScript转换为javascript,但我怀疑这是可能的,因为它似乎特定于MS应用程序和代码。我希望得到两种可能结果中的任何一种的帮助:a)实际上将代码转换为javascript,或b)证明将其转换为javascript目前是不可能的。

The specific VBScript statements that I consider too MS-specific are:

我认为特定的VBScript语句也是MS特定的:

set oExcel = CreateObject("Excel.Application")
set oBook = oExcel.Workbooks.Add
oBook.HTMLProject.HTMLProjectItems("Sheet1").Text = sHTML
oBook.HTMLProject.RefreshDocument()
oExcel.Visible = True
oExcel.UserControl = True

Has anyone interfaced javascript and Excel well enough for a solution to exist?

有没有人能够很好地连接javascript和Excel以便存在解决方案?

2 个解决方案

#1


Sure like this:-

当然是这样的: -

 var excel = new ActiveXObject("Excel.Application")
 var book = excel.Workbooks.Add()

 //The line below doesn't work in Excel 2007
 // book.HTMLProject.HTMLProjectItems["Sheet1"].Text = sHtml

 var sheet =  book.Sheets("Sheet1")
 sheet.Range("A2").Value = "Hello World"
 excel.Visible = true
 excel.UserControl = true

#2


You can do this only with JScript, not JavaScript- this will show you how. This may be fine if you are using only IE.

你只能用JScript而不是JavaScript来做到这一点 - 这会告诉你如何做。如果您只使用IE,这可能没问题。

#1


Sure like this:-

当然是这样的: -

 var excel = new ActiveXObject("Excel.Application")
 var book = excel.Workbooks.Add()

 //The line below doesn't work in Excel 2007
 // book.HTMLProject.HTMLProjectItems["Sheet1"].Text = sHtml

 var sheet =  book.Sheets("Sheet1")
 sheet.Range("A2").Value = "Hello World"
 excel.Visible = true
 excel.UserControl = true

#2


You can do this only with JScript, not JavaScript- this will show you how. This may be fine if you are using only IE.

你只能用JScript而不是JavaScript来做到这一点 - 这会告诉你如何做。如果您只使用IE,这可能没问题。