Export.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="http://knockoutjs.com/downloads/knockout-3.2.0.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="https://netdna.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<script src="scripts/vendor/wijmo.min.js" type="text/javascript"></script>
<script src="scripts/vendor/wijmo.input.min.js" type="text/javascript"></script>
<script src="scripts/vendor/wijmo.grid.min.js" type="text/javascript"></script>
<script src="scripts/vendor/wijmo.knockout.min.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="styles/vendor/wijmo.min.css" />
<script src="js/wijmo.grid.filter.min.js"></script>
<script src="js/wijmo.pdf.min.js"></script>
<script src="js/wijmo.grid.pdf.min.js"></script>
<script src="js/wijmo.xlsx.min.js"></script>
<script src="js/wijmo.grid.xlsx.min.js"></script>
<script src="js/jszip.min.js"></script>
<link href="styles/app.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="container">
<button id="btnExport" class="btn btn-default">
导出PDF
</button>
<button id="btnCreateDoc" class="btn btn-default">
创建PDF文档
</button>
<button id="btnExportxls" class="btn btn-default">
导出XLSX
</button>
<div id="theGrid" class="row">
<div class="col-md-6">
<h4>Result (live):</h4>
<div data-bind="wjFlexGrid: { itemsSource: data }"></div>
</div>
</div>
</div>
<script type="application/javascript">
onload = function() {
var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(',');
var data = [];
for (var i = 0; i < 200; i++) {
data.push({
id: i,
country: countries[i % countries.length],
sales: Math.random() * 10000,
expenses: Math.random() * 5000
});
}
var theGrid = new wijmo.grid.FlexGrid('#theGrid', {
autoGenerateColumns: false,
columns: [
{ binding: 'id', header: 'ID', width: 60 },
{ binding: 'country', header: 'Country', width: '2*'},
{ binding: 'sales', header: 'Sales', width: '*', format: 'n2'},
{ binding: 'expenses', header: 'Expenses', width: '*', format: 'n2'}
],
itemsSource: data
});
var f = new wijmo.grid.filter.FlexGridFilter(theGrid);
document.getElementById('btnExport').addEventListener('click', function() {
wijmo.grid.pdf.FlexGridPdfConverter.export(theGrid, 'LearnWijmo.pdf', {
maxPages: 10,
scaleMode: wijmo.grid.pdf.ScaleMode.PageWidth,
documentOptions: {
compress: true,
header: { declarative: { text: '\t&[Page] of &[Pages]' } },
footer: { declarative: { text: '\t&[Page] of &[Pages]' } },
info: { author: 'C1', title: 'Learn Wijmo' }
},
styles: {
cellStyle: { backgroundColor: '#ffffff' },
altCellStyle: { backgroundColor: '#f9f9f9' },
groupCellStyle: { backgroundColor: '#dddddd' },
headerCellStyle: { backgroundColor: '#eaeaea' }
}
});
});
document.getElementById('btnCreateDoc').addEventListener('click', function() {
var doc = new wijmo.pdf.PdfDocument({
compress: true,
header: { declarative: { text: '\t&[Page]\\&[Pages]' } },
ended: function (sender, args) {
wijmo.pdf.saveBlob(args.blob, 'LearnWijmoDoc.pdf');
}
});
doc.drawText('This is a FlexGrid');
wijmo.grid.pdf.FlexGridPdfConverter.draw(theGrid, doc, 400);
doc.end();
});
document.getElementById('btnExportxls').addEventListener('click', function() {
var book = wijmo.grid.xlsx.FlexGridXlsxConverter.save(theGrid, {
includeColumnHeaders: true,
includeRowHeaders: true
});
book.sheets[0].name = 'Learn Wijmo';
book.save('LearnWijmo.xlsx');
})
}
</script>
</body>
</html>
运行结果如图:




Demo下载地址