클라이언트 쪽 VBScript에서 Excel을 자동화하는 방법
이 문서에서는 사용자가 웹 페이지에서 단추를 클릭할 때 Microsoft Office Excel 또는 Microsoft Excel을 시작하고 자동화하는 Microsoft VBScript(Visual Basic, Scripting Edition) 클라이언트 쪽 코드를 보여 줍니다.
텍스트 편집기에서 다음 HTML 파일을 만들고 파일을 c:\excel.htm 저장합니다.
HTML<HTML> <BODY> <INPUT id=button1 name=button1 type=button value=Button> <SCRIPT LANGUAGE="VBScript"> sub button1_onclick() ' Launch Excel dim app set app = createobject("Excel.Application") ' Make it visible app.Visible = true ' Add a new workbook dim wb set wb = app.workbooks.add ' Fill array of values first... dim arr(19,9) ' Note: VBScript is zero-based for i = 1 to 20 for j = 1 to 10 arr(i-1,j-1) = i*j next next ' Declare a range object to hold our data dim rng set rng = wb.Activesheet.Range("A1").Resize(20,10) ' Now assign them all in one shot... rng.value = arr ' Add a new chart based on the data wb.Charts.Add wb.ActiveChart.ChartType = 70 'xl3dPieExploded wb.ActiveChart.SetSourceData rng, 2 ' xlColumns wb.ActiveChart.Location 2, "Sheet1" 'xlLocationAsObject ' Rotate it around... for i = 1 to 360 step 30 wb.activechart.rotation = i next ' Give the user control of Excel app.UserControl = true end sub </SCRIPT> </BODY> </HTML>
Microsoft Internet Explorer를 시작하고 주소 표시줄 에 c:\excel.htm 입력한 다음 Enter 키를 누릅니다.
페이지에 표시되는 단추를 클릭합니다.
참고
페이지에서 ActiveX 컨트롤에 대한 보안 경고가 표시되는 경우 예를 클릭합니다.