Skip to main content

Creating a interactive plotly in a spreadsheet


Inserting the Microsoft Web Browser Object

This post is for clarification on the Stack overflow Answer for Vestland.

Step 1: Open a blank spreadsheet and save it as [.xlsm] macro-enabled workbook
Step 2: Try inserting Microsoft web-browser Activex Control by following the below steps,
Refer to the below pictures for easy understanding
            Step 2.1: Click the Developer Tab
            Step 2.2: Click the Insert
            Step 2.3: Click MoreTools under Activex Control (Last Control)
            Step 2.4: Select Microsoft Web browser
            Step 2.5: Click OK
            Step 2.6: Draw a Rectangle for browser


you will get cannot insert Object error like this 
Can't insert Object
Error Snip

To fix this error you have to modify some registry settings.
1. Click Win + R to open Run
2. Type Regedit and click Enter to open the registry editor
3. Navigate to 

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\ClickToRun\REGISTRY\MACHINE\Software\Wow6432Node\Microsoft\Office\16.0\Common\COM Compatibility\{8856F961-340A-11D0-A96B-00C04FD705A2}

 4. Set the Dword to 0 from 400
5. Click OK (  Click Here for more details )

this will enable webbrowser object insertion

Now Close and Reopen the excel and Try inserting Microsoft web-browser Activex Control by above Pictures or Step 2 from the top

Now a WebBrowser is inserted to the excel sheet


Adding a Button and creating a macro for Opening Google




Step 1: Go to Developer
Step 2: Insert Button from form Controls
Step 3: Draw the button
Step 4: Right Click on Button and Click Assign Macro and Click New

Type the text insdide the macro:

Sub Button3_Click()
ActiveSheet.WebBrowser1.Navigate "http://www.google.com"
End Sub

Step 5: Save the macro and Click the button and now you can be able to see the google page and you can also perform some search.

Adding a Interactive poltly to excel

Step 1: Use the below python Code to generate a offline interactive plotly Graph

from plotly.subplots import make_subplots
import plotly
buttons =  [  dict( method='update', label='b1', visible=True, args=[{'y':[1,2,3]}] ),  
              dict( method='update', label='b2', visible=True, args=[{'y':[30,20,10]}] )]
fig = make_subplots()
fig.add_scatter(x=[2,4,6], y=[1,2,3]) \
    .update_layout(updatemenus=[{'buttons':buttons}]) \
    .update_xaxes(range=[-10, 10]) \
    .update_yaxes(range=[0, 30])
                              
plotly.offline.plot(fig, filename='test5.html')

Step 2: After running the python code a file named test5.html will be generated on the same place where the python code exists

Step 3: Now we need to edit the generated html file manually to add compatiblity meta tag

Important Step

Open the html in notepad and add the <meta http-equiv="X-UA-Compatible" content="IE=edge" /> save and close the file

Originally generated HTML file from plotly looks like this

<html>
<head><meta charset="utf-8" /></head>
<body>

Modified HTML with browser compatibility

<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
</head>
<body>
Step 4: Double click the file the html will be displayed in the browser


Step 5: Copy the link in the browser tab

file:///C:/Users/vignesh.rajendran/Desktop/test5.html

Step 6: Create one more form control button like we did for google above
Step 7: Assign a macro for it and type the macro code below

Sub Button4_Click()
ActiveSheet.WebBrowser1.Navigate "file:///C:/Users/vignesh.rajendran/Desktop/test5.html"
End Sub

Step 8: Save the macro and Excel
Step 9: Click the Button 4



Step 10: Right Click on the ribbon and click allow blocked content
Step 11: Click Yes to run active Content




Now you can able to see the interactive plotly graph on the spreadsheet, Feel free to post a comment on your queries

Further Steps:

1. Rename the button and macros name like Open Google and Open Plotly
2. Resize the Browser window by Clicking the design mode under developer tab
3. Moving the buttons to desired positions
4. Try using a online plotly
5. Reset the Registry back to 400 to block the java script again

My PC Details:
Windows 10
Excel : Microsoft Office 365 Pro Plus Package Version 1908




Comments

  1. Hello! This is extremely helpful, thank you for putting this guide together. I know it's been almost 2 years since you created it, but I have a question: were you ever able to get an embedded plotly graph in Excel to properly display hover labels? I was able to insert a plot into Excel successfully, but the hover labels do not seem to work. Other interaction works, but only once I click in the web browser window.

    ReplyDelete

Post a Comment

Popular posts from this blog

Devi Arts

  Peacock Art Black and White 21-June-2023 Another one From Peacock Series, but this one is Colorful  

Arduino Device USB2.0-serial Error / Arduino Serial Port Error

This is the post for Dayyan who is now facing this issue currently,hope he will slve using this Blog. After installing Arduino IDE,Portable or normal version.if no device is detected, Go to Control Panel-> Device manager or Goto Start menu and search for "devmgmt" click device manager if you see USB2.0-Serial on the Other Devices/Unknown Devices,its because of Duplicate China Chip instead of original FTDI,Because windows now stopped support for it. Solution: You need to install CH340G driver link for downloading driver if download doesn't work try to download it from the webpage Link ,It will be in chinese just click the download this,Hahahaha For more Details ->  Article Related to Serial port of Arduino I have found this after 5 hours of Debugging  Feel free to Comment..................... Learn Joyful.......