score:-1
i think without the use of ActiveX you cant read the excel file..I am not sayin that you cant read excel file file without ActiveX may be there is a way ,but i dont know that way so if you want to read using Activex then here is the code you can use for reading the excel file
<input type="button" id="btnSubmit" onclick="readdata(1, 2)" value="Submit" />
<script>
var xVal = 1;
var yVal = 2
function readdata(x,y) {
x = xVal;
y = yVal;
try {
var excel = new ActiveXObject("Excel.Application");
excel.Visible = false;
var excel_file = excel.Workbooks.Open("D:\\Test.xls");// alert(excel_file.worksheets.count);
var excel_sheet = excel_file.Worksheets("Sheet1");
for(i=0;i<5;i++)
{
var data = excel_sheet.Cells(i,2).Value;
drawWithexcelValue(data);
}
}
catch (ex) {
alert(ex);
}
</script>
it will run only in IE 9 and above ,and you have to activate activeX functionality from the settings ..
score:1
There is a Chart.js plugin chartjs-plugin-datasource that makes it easy to load data from Excel files.
Let's suppose you have an Excel file as shown below, and it is saved as mydata.xlsx
in the same directory as your HTML file:
+---------------+---------+----------+-------+-------+------+------+------+
| | January | February | March | April | May | June | July |
+---------------+---------+----------+-------+-------+------+------+------+
| Temperature | 7 | 7 | 10 | 15 | 20 | 23 | 26 |
+---------------+---------+----------+-------+-------+------+------+------+
| Precipitation | 8.1 | 14.9 | 41.0 | 31.4 | 42.6 | 57.5 | 36.0 |
+---------------+---------+----------+-------+-------+------+------+------+
Include Chart.js, SheetJS (js-xlsx) and chartjs-plugin-datasource in your page:
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0"></script>
<script src="https://cdn.jsdelivr.net/npm/xlsx@0.14.3/dist/xlsx.full.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datasource@0.1.0"> </script>
<canvas id="myChart"></canvas>
Then, specify mydata.xlsx
in your script.
var ctx = document.getElementsById("myChart");
var chart = new Chart(ctx, {
type: 'bar',
data: {
datasets: [{
type: 'line',
yAxisID: 'temperature',
backgroundColor: 'transparent',
borderColor: 'rgb(255, 99, 132)',
pointBackgroundColor: 'rgb(255, 99, 132)',
tension: 0,
fill: false
}, {
yAxisID: 'precipitation',
backgroundColor: 'rgba(54, 162, 235, 0.5)',
borderColor: 'transparent'
}]
},
plugins: [ChartDataSource],
options: {
scales: {
yAxes: [{
id: 'temperature',
gridLines: {
drawOnChartArea: false
}
}, {
id: 'precipitation',
position: 'right',
gridLines: {
drawOnChartArea: false
}
}]
},
plugins: {
datasource: {
url: 'mydata.xlsx'
}
}
}
});
score:4
Here is another perspective on this problem, instead of reading an Excel file with JavaScript, you could directly use JavaScript in Excel with the help of the Funfun Excel add-in. Basically, Funfun is a tool that allows you to use JavaScript in Excel so you could use libraries like Chart.js to plot chart from the data in the spreadsheet.
Basically, what you need to do is
1). Insert the Funfun add-in from Office Add-ins store
2). Create a new Funfun or load a sample from Funfun online editor
3). Write JavaScrip code as you do in any other JavaScript editor. In this step, in order to directly use the data from the spreadsheet, you need to write some JSON I/O to make Excel cell reference. The place this value is in Setting-short But this would be just several lines. For example, let's assume we have some data like below in the spreadsheet. The Average hours is in cell A1.
Average hours Jan Feb Mar Apr
Baby Jones 93.5 81 94.5 95.5
Joanne Jones 91.5 90 88.5 85.5
In this case, the JSON I/O value would be:
{
"months": "=C6:G6",
"manager1": "=C7:G7",
"manager2": "=C8:G8"
}
You could check the Funfun documentation for more explanation.
4). Run the code to plot chart
Here is a sample chart that I made using JavaScript(Chart.js) and Excel data on Funfun online editor. You could check it on the link below. You could also easily load it to your Excel as described in Step2.
https://www.funfun.io/1/edit/5a365e7c74efa7334ff272a6
Disclosure: I'm a developer from Funfun.
score:10
Source: stackoverflow.com
Related Query
- How can I read an Excel File with JavaScript (without ActiveXObject)
- How to Export JavaScript Chart to Excel file (HighCharts)
- How can i export row data from highchart to excel file and not csv?
- How can I capture all points belonging to the same series with the same xAxis value without a loop?
- How to have multiple highcharts with different series data in vuejs without repeating code
- How can I pass this array to a javascript function in an html.erb file, without erb evaluating the Date.UTC?
- Export HighChart as an image in excel file together with the other page contents
- How can I configure the legend with a specific height in highstock?
- How can I hide ALL series with the same ID with a button on highcharts? (line graph)
- JavaScript code inside TypeScript file .ts not working
- How can I force ticks/grid lines on a Highcharts datetime X axis to arbitrarily line up with data points?
- How can i get the json data with the specific between Year?
- c# WPF Webbrowser with Highchart, Javascript from external source not working "An error has occurred in the script on this page"
- How Can I Hide a Pie Chart's Slice in HighCharts Without Removing It From the Legend?
- How can I make a graph with highcharts from csv file?
- how to display 2 same highcharts without duplicate the code
- How can I align gridlines with dots in Highcharts
- How to access angular scope variable in JavaScript file
- How I can customize the file name when exporting using the plug-in CSV in Highcharts?
- With HighCharts, how can I have the same tooltip formatter as my y axis
- How can I deal with Highcharts inline styles to prevent Content-Security-Policy violations?
- How to read and insert correct highchart number in selectors using Selenium Webdriver with Python?
- How can I update two highcharts with one dropdown menu?
- How can I hide non-selected series and axes when using XY zoom with highcharts?
- How can i add element with attributes to SVG using jquery
- passing formatting JavaScript code to HighCharts with JSON
- How to update a Javascript object with a function
- How can I make milestone lines with a GANTT chart using the highcharts library?
- How can I have both a legend and data labels, with different labels, in Highcharts?
- How can I show all Timeline Highcharts data without any overlapping?
More Query from same tag
- Issue with creating a highchart funnel chart in react
- JQuery Highcharts - dates being picked up in US format not UK
- How to add a header or logo to highcharts exported PDF?
- How to create a drilleable bar graph in jsp page using open source charts API
- How can I specify custom end markers in a scatter series with Highcharts 9?
- passing json values to highcharts from .net code behind
- Unable to plot two piechart using Highchart
- Highcharts click events not firing when displaying multiple line series
- Highcharts polar chart - zero at centre
- How to Load More Than One CSV Using Highcharts Data Module
- Highcharts: aligning data labels on the same line in bar charts
- How to export a Highchart chart to PDF thanks to a button outside the chart?
- Highchart's selection-function updating with delay
- Customize tooltip and format the number to 2 decimal places of highcharts
- Highcharts column animation issue
- Highcharts pie chart issue (gaps between pie slices)
- Highcharts two charts on page
- Negative color with area color fill and yAxis
- HighCharts HighStocks event flag is obscured by chart border
- Styled Mode : Color theme for bar
- Highcharts smooth transition on data update using Angular and ng-highcharts
- highchartjs create label for column
- Issue With Highcharts x-axis label
- Highmaps get() function on a secondary series
- Highcharts - TickInterval with datetime values
- Highcharts : remove custom legend tooltip from export
- Highcharts area chart with lazy_chart ruby gem
- Highcharts read data from XML throught attributes
- Difference between setExtremes and afterSetExtremes in HighStock
- Highcharts/Highstock dynamically add/remove multiple series