1.引入bootstrap-table-export.js 可自己在gitshang下载
2.引入tableExport.js 需要在这个文件中增加一部分代码,用于支持ie8导出,具体添加代码如下:
// Header
$(el).find('thead').first().find(defaults.theadSelector).each(function() {
excel += ""; ';
ForEachVisibleCell(this, 'th,td', rowIndex,
function(cell, row, col) {
if (cell != null) {
excel += "" + parseString(cell, row, col)+ " ";
}
});
rowIndex++;
excel += '
});//在这之后添加一下代码:
// Row Vs Column
var rowCount=1;
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);
xlsheet.Range(xlsheet.Cells(1, 1), xlsheet.Cells(1, 8)).mergecells = true;
xlsheet.Range(xlsheet.Cells(1, 1), xlsheet.Cells(1, 8)).value = "局长工作安排会议列表";
xlsheet.Rows(1).Font.Size = 14;
xlsheet.Rows(1).Font.Name = "黑体";
xlsheet.Columns("A:H").ColumnWidth = 18;
//
xlsheet.Columns(1).NumberFormatLocal = "@";
xlsheet.Columns(2).NumberFormatLocal = "@";
xlsheet.Columns(3).NumberFormatLocal = "@";
xlsheet.Columns(4).NumberFormatLocal = "@";
xlsheet.Columns(5).NumberFormatLocal = "@";
xlsheet.Columns(6).NumberFormatLocal = "@";
xlsheet.Columns(7).NumberFormatLocal = "@";
xlsheet.Columns(8).NumberFormatLocal = "@";
// 设置标题栏
xlsheet.Cells(2, 1).Value = "序号";
xlsheet.Cells(2, 2).Value = "参会人员";
xlsheet.Cells(2, 3).Value = "会议内容";
xlsheet.Cells(2, 4).Value = "会议地点";
xlsheet.Cells(2, 5).Value = "会期开始时间";
xlsheet.Cells(2, 6).Value = "会期结束时间";
xlsheet.Cells(2, 7).Value = "录入人";
xlsheet.Cells(2, 8).Value = "录入日期";
$(el).find('tbody').first().find(defaults.tbodySelector).each(function() {
//
ForEachVisibleCell(this, 'td', rowIndex,
function(cell, row, col) {
if (cell != null) {
xlsheet.Cells(rowIndex + 2, col).Value =parseString(cell, row, col);
}
});
xlsheet.Columns.AutoFit;
xlsheet.Range(xlsheet.Cells(1, 1), xlsheet.Cells(1, 8)).HorizontalAlignment = -4108;// 居中
/* xlsheet.Range(xlsheet.Cells(1, 1), xlsheet.Cells(1, 8)).VerticalAlignment = -4108;
xlsheet.Range(xlsheet.Cells(2, 1), xlsheet.Cells(rowNum + 1, 8)).Font.Size = 10;
xlsheet.Range(xlsheet.Cells(2, 1), xlsheet.Cells(rowNum + 1, 8)).Borders(3).Weight = 2; // 设置左边距
xlsheet.Range(xlsheet.Cells(2, 1), xlsheet.Cells(rowNum + 1, 8)).Borders(4).Weight = 2;// 设置右边距
xlsheet.Range(xlsheet.Cells(2, 1), xlsheet.Cells(rowNum + 1, 8)).Borders(1).Weight = 2;// 设置顶边距
xlsheet.Range(xlsheet.Cells(2, 1), xlsheet.Cells(rowNum + 1, 8)).Borders(2).Weight = 2;// 设置底边距
xls.UserControl = true; // 很重要,不能省略,不然会出问题 意思是excel交由用户控制
xls = null;
xlBook = null;
xlsheet = null;*/
rowCount++;
rowIndex++;
说明:就是以ActiveX控件进行导出,bootstrap-table插件的导出方式貌似不支持ie8,今天做项目遇到了特意写下来与大家分享,共同进步!