js导出数据到excel,设置单元格数据格式为文本;数字000101;变成了101
方法:
问题:数字000101;导出excel变成了101;;;;科学计数法也是这样
解决方法: 1: xlSheet.Cells(num,8).NumberFormatLocal = "@";//设置导出为文本
2: xlSheet.Cells(num, 9).Value = "‘"+agencyname; //你可以在导出的时候给数据前加一个英文半角的‘逗号
// 将数据导出到excel表格
function leadingOut(stampGrid) {
var selectData = stampGrid.getSelectionModel().getSelection();
if (selectData.length <= 0) {
alert("请至少选择一个印章信息!");
rehresh();
return;
}
try {
var xls = new ActiveXObject("Excel.Application");
} catch (e) {
alert("要打印该表,您必须安装Excel电子表格软件,同时浏览器须使用“ActiveX 控件”,您的浏览器须允许执行控件。 请点击【帮助】了解浏览器设置方法!");
return "";
}
xls.visible = true; // 设置excel为可见
var xlBook = xls.Workbooks.Add;
var xlSheet = xlBook.Worksheets(1);
var num = 2;
var title = [ ‘ID‘, ‘行政区划‘, ‘凭证类型‘, ‘位置编号‘, ‘位置名称‘,
‘证书SN‘, ‘证书DN‘, ‘单位编码‘, ‘单位名称‘, ‘接收机构‘ ];
// 标题栏
for ( var i = 0; i < title.length; i++) {
var j = i + 1;
xlSheet.Cells(1, j).Value = title[i];
}
if (sign_type == 1) {
xlSheet.Cells(1, 11).Value = ‘印章ID‘;
}
for ( var i = 0; i < selectData.length; i++) {
id = selectData[i].data.id;
admdivcode = selectData[i].data.admdivcode;
vt_code = selectData[i].data.vt_code;
stamp_no = selectData[i].data.stamp_no;
stamp_name = selectData[i].data.stamp_name;
cert_sn = selectData[i].data.cert_sn;
cert_dn = selectData[i].data.cert_dn;
agencycode = selectData[i].data.agencycode;
agencyname = selectData[i].data.agencyname;
receive_org = selectData[i].data.receive_org;
// 内容栏
xlSheet.Cells(num, 1).Value = id;
xlSheet.Cells(num, 2).Value = admdivcode;
xlSheet.Cells(num, 3).Value = vt_code;
xlSheet.Cells(num, 4).Value = stamp_no;
xlSheet.Cells(num, 5).Value = stamp_name;
xlSheet.Cells(num, 6).Value = cert_sn;
xlSheet.Cells(num, 7).Value = cert_dn;
xlSheet.Cells(num,8).NumberFormatLocal = "@";//设置导出为文本
xlSheet.Cells(num, 8).Value = agencycode;
xlSheet.Cells(num, 9).Value = "‘"+agencyname;
xlSheet.Cells(num, 10).Value = receive_org;
num++;
}
xlSheet.Columns.AutoFit;
xls.ActiveWindow.Zoom = 75;
rehresh();
xls.UserControl = true; // excel交由用户控制
xls = null;
xlBook = null;
xlSheet = null;
Ext.Msg.alert("系统提示", "导出成功");
rehresh();
}