Store Jscript values in Excel - excel

I'm trying to transfer the values stored in a JScript matrix to Excel. The problem is how I should initialize the current Excel Workbook that is opened.
For previous works, in python the code is:
import clr
clr.AddReference("Microsoft.Office.Interop.Excel")
import Microsoft.Office.Interop.Excel as Excel
from System.Runtime.InteropServices import Marshal
ex = Marshal.GetActiveObject("Excel.Application")
ex.Visible = True
wb = ex.ActiveWorkbook
ws_data = wb.Worksheets('name')
So my intention is "translate" this code into Jscript to set the values of my matrix in Excel

There is no "global" conversion of this code into JavaScript. Only Internet Explorer supports something called "Active X objects". In other browsers direct communication between JavaScript and Excel is not possible (at least not "out of the box").
In Internet Explorer you can use the following code:
var ExcelApp = new ActiveXObject("Excel.Application");
See more i.e. here ActiveXObject Object (JavaScript)

Related

Trying to create an Entity Relationship Database from Excel using Visio Standard

I'm trying to use my company's software, Visio Standard, to create an entity relationship database using Excel. Usually the team has been creating this manually due to not having access to the Professional versions. With a mulitude of entities, the process is extremely tedious doing this one by one. I am trying to import from Excel to Visio without that pro version.
Theoretically the excel template would have Entity Name, Entity Structure (P'ship, Corp, DRE, Individual, ect.) and whatever else information needed to automatically populate into excel.
I have a background in VBA so that could be utilized, I just keep running into roadblocks due to the lack of tabs that the standard version has, including the main Data tab for import.
Is there any way I can import my data from Excel into Visio then run a code to convert it into shapes? What about my own custom template?
We make entity relationship diagrams often so one template would not work. We have a standard shapes & stencils that is used across the board, but the ERD is never the same. I thought I needed a template but I realized that I can't convert a personal template to a wizard or import an excel to the template that the template becomes quite useless.
#Surrogate My idea is that I want to pull the data from a template in excel to automatically create the ERD (or close to it) to save a large sum of time creating those entities through the shapes one by one. I think the template in Excel being so basic, with header columns for the Name of the Entity, Shape to use, hierarchy ladder; VBA does come into play pretty easily, just unsure how to mess around with that since I can't import excel into Visio through the standard version
#y4cine I am stuck because I cannot import data from excel in the standard version.
#TimWilliams I'm not capable of poaching to paying for the pro version, so regardless of the "fun" I would like to see if I could work around the pro version to do what the ERD/wizard can do, even if it requires a large VBA macro.
because I cannot import data from excel in the standard version
This example uses early binding.
In VBA you need to set a reference to the Excel Library.
It sets prop values in already existing shapes. The link being the shape ID.
If you rather need to draw new shapes, I' recommend using a master.
something like:
dim oMaster as master
dim oStencil as document
set oStencil = Application.Documents("myStencil")
set oMaster = oStencil.Masters("myMaster")
then inside the loop:
define some coordinates for x and y
set shp = activepage.drop(oMaster,x,y)
The function:
Public Function excelImport(filename As String) As Boolean
Dim xlsWorkbook As Excel.Workbook
Dim xlsSheet As Excel.Worksheet
Dim shp As Visio.Shape
Dim num_rows As Integer
Dim row As Integer
Dim shpID As String
Set xlsWorkbook = Excel.Workbooks.Open(filename)
Set xlsSheet = xlsWorkbook.Worksheets(1)
num_rows = xlsSheet.Range("A65000").End(xlUp).row
For row = 2 To num_rows
shpID = xlsSheet.Range("P" & row).FormulaR1C1
If Not shpID = "" Then
Set shp = ActivePage.Shapes.ItemFromID(CLng(shpID))
shp.Cells("prop.SoAndSo").Formula = Chr(34) & xlsSheet.Range("A" & row).FormulaR1C1 & Chr(34)
End If
Next row
xlsSheet.Application.Quit
Set xlsSheet = Nothing
Set xlsWorkbook = Nothing
excelImport = True
End Function

Error accessing external function select - Excel sheet in powerbuilder

This is the my script.
Im getting error in select method.
Please help.
Thanks in advance
OLEObject xlApp,xls_1,xls_2
integer li_rc
string ls_filepath = "D:\backup\"
xlApp = Create OLEObject
li_rc = xlApp.ConnectToNewObject( "Excel.Application" )
if li_rc < 0 then
MessageBox("Connect to Excel Failed !",string(li_rc))
Return -1
end if
xlApp.Application.Workbooks.Open(ls_filepath+'\test1.xls')
xlApp.Application.Workbooks.Open(ls_filepath+'\test2.xls')
xls_1 = xlApp.Application.Workbooks[1].Worksheets[1]
xls_2 = xlApp.Application.Workbooks[2].Worksheets[1]
xls_2.activate()
xls_1 .activate()
xls_2.rows("1:8").copy()
xls_1 .Rows("1:8").Select()
xls_1 .paste()
xlApp.Application.workbooks[1].SaveAs(ls_filepath+"\test3.xls")
xlApp.Application.WorkBooks.close()
xlApp.Application.WorkBooks.Application.quit()
destroy xlApp
destroy xls_1
destroy xls_2
Return 1
Welcome to the wonderful world of dynamic objects (weak typing)
These kinds of things require more conscientious development techniques particularly checking the type of object, property, function or whatever your dot nation has navigated you in the neighborhood of.
But some OLE objects are weak on functions to interrogate the entire object model of a dynamic object forcing you to rely heavily on Microsoft OLE documentation which is boring and often version specific. I think your issue would be easier seen by a VBA and/or Visual Basic Scripting or Excel OLE expert.
But in the name of a PowerBuilder solution. It sometimes helps to wrap operations on dynamic objects in TRY..CATCH..FINALLY clause and then add your own code to handle the various OLE Exceptions and prevent PB from crashing each time your dot nation doesn't match what was expected.

VBA CountIf external document

Following from my previous question, I am now struggling to create a working Application.CountIf function. I am using the following code to access the file as "xl0":
'DATABASE ACCESS
Dim xl0 As New Excel.Application
Dim xlw As New Excel.Workbook
Dim db_directory As String
db_directory = "R:\New Quality Management System\xls\Supplier\Non-Conformance\Supplier Non-Conformance Database.xlsm"
Set xlw = xl0.Workbooks.Open(db_directory)
I can create a function to search the same open document no problem...
Test = Application.CountIf(Range("B:B"), Report_ID)
MsgBox (Test)
...but neither of the methods I've tried for searching in the document open in the background have worked...
Test = Application.CountIf(xlw.Sheets("SNCR Log").Range("B:B"), Report_ID)
...and...
Test = xlw.Sheets("SNCR Log").Application.CountIf(Range("B:B"), Report_ID)
What am I missing?
Just a guess, did not test it, but as Application refers to your current open application and you want to search within the xl0 application try
xl0.CountIf(...)
and see if that helps.

Add sparklines to excel with matlab

With MATLAB I can start a COM server and programmatically write to an Excel workbook. However, I can't figure out a way to add sparklines (suggestions appreaciated):
% Open new workbook
excel = actxserver('excel.application');
excel.visible = 1;
wrkbook = excel.Workbooks.Add();
sheet = wrkbook.Sheets.Item(1);
% Write some data
sheet.Range('B1:Z1').Value = rand(1,25);
Here is the problem:
% Add column sparklines to 'A1', type 'xlSparkColumn' and DataSource: 'B1:Z1'
sheet.Range('A1').SparklineGroups.Add('xlSparkColumn','B1:Z1')
I get the following error:
Error using Interface.Microsoft_Excel_15.0_Object_Library.SparklineGroups/Add
Error: Object returned error code: 0x800A03EC
Close/cleanup
% Close without saving
wrkbook.Saved = 1;
wrkbook.Close
excel.Quit
delete(excel)
Reference to SparklineGroup Object (Excel). I am on win7 64bit, R2013a and Excel 2013.
Try:
xlSparkColumn = 2;
sheet.Range('A1').SparklineGroups.Add(xlSparkColumn,'B1:Z1')
In the future, if you want to figure out the corresponding value for a certain constant/enum, use the IL DASM tool as shown in these posts.
EDIT
Ok it turns out that the enumeration xlSparkColumn was not the real issue here, you could either specify it as a string argument or pass the underlying integer value for the enum.
The problem as you mentioned in the comments is that you had the R1C1 reference style set instead of the default A1 reference style, thus the range specified in your call was not valid in that format.
Either of these will work:
excel.ReferenceStyle = 'xlR1C1';
sheet.Range('A1').SparklineGroups.Add('xlSparkColumn','R1C2:R1C26')
excel.ReferenceStyle = 'xlA1';
sheet.Range('A2').SparklineGroups.Add('xlSparkColumn','B1:Z1')

Creating a new Excel File in pywin32

I'm writing a program that, summarized, takes a notepad file and saves it as a excel file.
Right now my program opens up a blank excel file I have created, just "Book1.xls":
xlApp = Dispatch("Excel.Application")
xlApp.Visible=0
xlWb = xlApp.Workbooks.Open(file_path+"/Book1.xls")
workBook = xlApp.ActiveWorkbook
sheet = xlApp.ActiveSheet
and it uses Book1.xls to write into and format as is required, then saves it as another file name using
workBook.SaveAs(new_file_path+'/UpdatedSheet.xls')
I want to know how to simply create a new excel file to write to, then save as a file. Without the need of having Book1.xls already created in a specific directory.
You can create a new workbook using the Add method of the Workbooks object:
>>> import win32com.client as win32
>>> excel = win32.Dispatch("Excel.Application")
>>> workbook = excel.Workbooks.Add()
>>> workbook.SaveAs(new_file_path+'/UpdatedSheet.xls')

Resources