4 个解决方案
#1
楼上的,知道后告诉我下
#2
1.把以下文件保存为js文件;
2.引用时 ExcelOut(id),id为Grid的id,
function ExcelOut(id) {
var gView = Efs.getExt(id).getView();
var rows = gView.getRows().length; //行数
var columncount = Efs.getExt(id).getColumnModel().getColumnCount(); //列数
// var header = gView.getHeaderCell(2).innerText; //表括头
// var data = gView.getCell(0, 0).firstChild.innerHTML; //数据内容
var r = 1;
if (gView.getHeaderCell(1).innerText == " ") {
r = 2;
}
var oXL = new ActiveXObject("Excel.Application");
//创建AX对象excel
var oWB = oXL.Workbooks.Add();
//获取workbook对象
var oSheet = oWB.ActiveSheet;
//激活当獭前sheet
var i = r;
for (var j= 1; i < columncount; j++,i++) {
oSheet.Cells(1, j).value = gView.getHeaderCell(i).innerText;
}
for (var k = 0, l = 2; k < rows; k++, l++) {
i = r;
for (var x = 1; i < columncount; x++, i++) {
var y = gView.getCell(k, i).firstChild.innerHTML;
if (y == null || y == " ") {
y = "";
}
oSheet.Cells(l, x).value = "'"+y;
}
}
oXL.Visible = true;
}
2.引用时 ExcelOut(id),id为Grid的id,
function ExcelOut(id) {
var gView = Efs.getExt(id).getView();
var rows = gView.getRows().length; //行数
var columncount = Efs.getExt(id).getColumnModel().getColumnCount(); //列数
// var header = gView.getHeaderCell(2).innerText; //表括头
// var data = gView.getCell(0, 0).firstChild.innerHTML; //数据内容
var r = 1;
if (gView.getHeaderCell(1).innerText == " ") {
r = 2;
}
var oXL = new ActiveXObject("Excel.Application");
//创建AX对象excel
var oWB = oXL.Workbooks.Add();
//获取workbook对象
var oSheet = oWB.ActiveSheet;
//激活当獭前sheet
var i = r;
for (var j= 1; i < columncount; j++,i++) {
oSheet.Cells(1, j).value = gView.getHeaderCell(i).innerText;
}
for (var k = 0, l = 2; k < rows; k++, l++) {
i = r;
for (var x = 1; i < columncount; x++, i++) {
var y = gView.getCell(k, i).firstChild.innerHTML;
if (y == null || y == " ") {
y = "";
}
oSheet.Cells(l, x).value = "'"+y;
}
}
oXL.Visible = true;
}
#3
楼主写的对着呢 将显示给成Save()能好点 结贴吧
#4
楼主问题搞定没?给分享下呗
#1
楼上的,知道后告诉我下
#2
1.把以下文件保存为js文件;
2.引用时 ExcelOut(id),id为Grid的id,
function ExcelOut(id) {
var gView = Efs.getExt(id).getView();
var rows = gView.getRows().length; //行数
var columncount = Efs.getExt(id).getColumnModel().getColumnCount(); //列数
// var header = gView.getHeaderCell(2).innerText; //表括头
// var data = gView.getCell(0, 0).firstChild.innerHTML; //数据内容
var r = 1;
if (gView.getHeaderCell(1).innerText == " ") {
r = 2;
}
var oXL = new ActiveXObject("Excel.Application");
//创建AX对象excel
var oWB = oXL.Workbooks.Add();
//获取workbook对象
var oSheet = oWB.ActiveSheet;
//激活当獭前sheet
var i = r;
for (var j= 1; i < columncount; j++,i++) {
oSheet.Cells(1, j).value = gView.getHeaderCell(i).innerText;
}
for (var k = 0, l = 2; k < rows; k++, l++) {
i = r;
for (var x = 1; i < columncount; x++, i++) {
var y = gView.getCell(k, i).firstChild.innerHTML;
if (y == null || y == " ") {
y = "";
}
oSheet.Cells(l, x).value = "'"+y;
}
}
oXL.Visible = true;
}
2.引用时 ExcelOut(id),id为Grid的id,
function ExcelOut(id) {
var gView = Efs.getExt(id).getView();
var rows = gView.getRows().length; //行数
var columncount = Efs.getExt(id).getColumnModel().getColumnCount(); //列数
// var header = gView.getHeaderCell(2).innerText; //表括头
// var data = gView.getCell(0, 0).firstChild.innerHTML; //数据内容
var r = 1;
if (gView.getHeaderCell(1).innerText == " ") {
r = 2;
}
var oXL = new ActiveXObject("Excel.Application");
//创建AX对象excel
var oWB = oXL.Workbooks.Add();
//获取workbook对象
var oSheet = oWB.ActiveSheet;
//激活当獭前sheet
var i = r;
for (var j= 1; i < columncount; j++,i++) {
oSheet.Cells(1, j).value = gView.getHeaderCell(i).innerText;
}
for (var k = 0, l = 2; k < rows; k++, l++) {
i = r;
for (var x = 1; i < columncount; x++, i++) {
var y = gView.getCell(k, i).firstChild.innerHTML;
if (y == null || y == " ") {
y = "";
}
oSheet.Cells(l, x).value = "'"+y;
}
}
oXL.Visible = true;
}
#3
楼主写的对着呢 将显示给成Save()能好点 结贴吧
#4
楼主问题搞定没?给分享下呗