var idTmr = "";
Ext.ux.Grid2Excel = {
Save2Excel : function(grid) {
var cm = grid.getColumnModel();
var store = grid.getStore();
var it = store.data.items;
var rows = it.length;
var oXL = new ActiveXObject("Excel.application");
var oWB = oXL.Workbooks.Add();
var oSheet = oWB.ActiveSheet;
for ( var i = 0; i < cm.getColumnCount(); i++) {
if (!cm.isHidden(i)) {
oSheet.Cells(1, i + 1).value = cm.getColumnHeader(i);
}
for ( var j = 0; j < rows; j++) {
r = it[j].data;
var v = r[cm.getDataIndex(i)];
var fld = store.recordType.prototype.fields.get(cm
.getDataIndex(i));
if (fld.type == 'date') {
v = v.format('Y-m-d');
}
oSheet.Cells(2 + j, i + 1).value = "'"+v;
}
}
/* Application.ActiveSheet.Name ‘返回活动工作表的名称
Application.ActiveWindow.Caption ‘返回活动窗口的标题
Application.ActiveWorkbook.Name ‘返回活动工作簿的名称*/
oSheet.Application.ActiveWindow.Caption = "excelName";
oSheet.Application.ActiveSheet.name= "excelName";
[color=red][b]//oSheet.Application.ActiveWorkbook.Name = "excelName";[/b][/color]
oSheet.Columns.AutoFit;
oXL.ActiveWindow.Zoom = 75;
oXL.UserControl = true;
oXL.DisplayAlerts = false;
oXL.Save();
oXL.DisplayAlerts = true;
oXL.Quit();
oXL = null;
idTmr = window.setInterval("Cleanup();", 1);
}
};
function Cleanup() {
window.clearInterval(idTmr);
CollectGarbage();
};
为什么导出的Excle文件名没有办法修改,只能是系统默认的Book1,Book2.....等等。
Ext.ux.Grid2Excel = {
Save2Excel : function(grid) {
var cm = grid.getColumnModel();
var store = grid.getStore();
var it = store.data.items;
var rows = it.length;
var oXL = new ActiveXObject("Excel.application");
var oWB = oXL.Workbooks.Add();
var oSheet = oWB.ActiveSheet;
for ( var i = 0; i < cm.getColumnCount(); i++) {
if (!cm.isHidden(i)) {
oSheet.Cells(1, i + 1).value = cm.getColumnHeader(i);
}
for ( var j = 0; j < rows; j++) {
r = it[j].data;
var v = r[cm.getDataIndex(i)];
var fld = store.recordType.prototype.fields.get(cm
.getDataIndex(i));
if (fld.type == 'date') {
v = v.format('Y-m-d');
}
oSheet.Cells(2 + j, i + 1).value = "'"+v;
}
}
/* Application.ActiveSheet.Name ‘返回活动工作表的名称
Application.ActiveWindow.Caption ‘返回活动窗口的标题
Application.ActiveWorkbook.Name ‘返回活动工作簿的名称*/
oSheet.Application.ActiveWindow.Caption = "excelName";
oSheet.Application.ActiveSheet.name= "excelName";
[color=red][b]//oSheet.Application.ActiveWorkbook.Name = "excelName";[/b][/color]
oSheet.Columns.AutoFit;
oXL.ActiveWindow.Zoom = 75;
oXL.UserControl = true;
oXL.DisplayAlerts = false;
oXL.Save();
oXL.DisplayAlerts = true;
oXL.Quit();
oXL = null;
idTmr = window.setInterval("Cleanup();", 1);
}
};
function Cleanup() {
window.clearInterval(idTmr);
CollectGarbage();
};
为什么导出的Excle文件名没有办法修改,只能是系统默认的Book1,Book2.....等等。