javascript操作excel文件的例子
发布时间:2015-08-15 编辑:jiaochengji.com
分享一个javascript操作excel文件的例子,使用activexobject组件操作excel文件,通过本实例掌握javascript操作excel的方法,感兴趣的朋友参考下。
以下方法生成的分析图与数据是分离的,当数据区的值改变时,分析图是不会随之改变的,如果要一起改变,就只能全部用无所不能的javascript来excel了。
例子:
复制代码 代码示例:
<html>
<body>
<script lanage="javascript">
function createexcel()
{
var exceldemo = new activexobject("excel.application");
exceldemo.visible = true;
var workbook = exceldemo.workbooks.add();
var sheet = workbook.activesheet;
sheet.cells(1,1).value = "1月";
sheet.cells(2,1).value = "2月";
sheet.cells(3,1).value = "3月";
sheet.cells(4,1).value = "4月";
sheet.cells(1,2).value = "120";
sheet.cells(2,2).value = "250";
sheet.cells(3,2).value = "310";
sheet.cells(4,2).value = "80";
exceldemo.visible = true;
exceldemo.usercontrol = true;
oresizerange = sheet.range("b1:b4");
var chart = sheet.parent.charts.add();
chart.chartwizard(oresizerange, -4100, null, 2);
chart.seriescollection(1).xvalues = sheet.range("a1","a4");
chart.seriescollection(1).name = '月报';
chart.location(2, sheet.name);
sheet.shapes("chart 1").top = sheet.rows(10).top;
sheet.shapes("chart 1").left = sheet.columns(2).left;
}
</script>
<p><input id=button1 type=button value="生成excel" onclick="createexcel()"></p>
</body>
</html>
<body>
<script lanage="javascript">
function createexcel()
{
var exceldemo = new activexobject("excel.application");
exceldemo.visible = true;
var workbook = exceldemo.workbooks.add();
var sheet = workbook.activesheet;
sheet.cells(1,1).value = "1月";
sheet.cells(2,1).value = "2月";
sheet.cells(3,1).value = "3月";
sheet.cells(4,1).value = "4月";
sheet.cells(1,2).value = "120";
sheet.cells(2,2).value = "250";
sheet.cells(3,2).value = "310";
sheet.cells(4,2).value = "80";
exceldemo.visible = true;
exceldemo.usercontrol = true;
oresizerange = sheet.range("b1:b4");
var chart = sheet.parent.charts.add();
chart.chartwizard(oresizerange, -4100, null, 2);
chart.seriescollection(1).xvalues = sheet.range("a1","a4");
chart.seriescollection(1).name = '月报';
chart.location(2, sheet.name);
sheet.shapes("chart 1").top = sheet.rows(10).top;
sheet.shapes("chart 1").left = sheet.columns(2).left;
}
</script>
<p><input id=button1 type=button value="生成excel" onclick="createexcel()"></p>
</body>
</html>
您可能感兴趣的文章:
javascript 操作excel代码示例
javascript excel操作类实现代码
[C#]结束Excel的进程的方法
javascript操作excel文件的例子
c#(asp.net)连接excel的实例代码
Farpoint操作excel的用法举例
解决php下载excel无法打开的问题
javascript操作excel文件方法详解
PHP导入与导出Excel文件的方法
php导出word文档与excel表格文件
[关闭]