, 난 그냥 .XLS로 해당 개체를 내보내거나 믿을수이 같은 접근 방식을 많이 사용 .csv로하려면, 내 컨트롤러에서 개체를했습니다 :Angular JS - Javascript 개체를 XLS 파일로 내보내는 방법? 사실
HTML을
<script src="https://rawgithub.com/eligrey/FileSaver.js/master/FileSaver.js" type="text/javascript" />
<div ng-controller="myCtrl">
<button ng-click="exportData()">Export</button>
<br />
<div id="exportable">
<table width="100%">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>DoB</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in items">
<td>{{item.name}}</td>
<td>{{item.email}}</td>
<td>{{item.dob | date:'MM/dd/yy'}}</td>
</tr>
</tbody>
</table>
</div>
</div>
자바 스크립트
function myCtrl($scope) {
$scope.exportData = function() {
var blob = new Blob([document.getElementById('exportable').innerHTML], {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
});
saveAs(blob, "Report.xls");
};
$scope.items = [{
name: "John Smith",
email: "[email protected]",
dob: "1985-10-10"
}, {
name: "Jane Smith",
email: "[email protected]",
dob: "1988-12-22"
}, {
name: "Jan Smith",
email: "[email protected]",
dob: "2010-01-02"
}, {
name: "Jake Smith",
email: "[email protected]",
dob: "2009-03-21"
}, {
name: "Josh Smith",
email: "[email protected]",
dob: "2011-12-12"
}, {
name: "Jessie Smith",
email: "[email protected]",
dob: "2004-10-12"
}]
}
하지만이 거기 매겨진 tables.is와 직접 (이 예를 들어 $의 scope.item에서) 개체를 내보낼 수있는 방법 파일에 작동 (XLS , CSV)?
이것은 훌륭한 솔루션입니다. 정말 감사드립니다. 내부 객체와 컬렉션을 파싱하는 간단한 솔루션이 있습니까? –
예. SELECT 연산자와 비슷한 SEARCH 연산자를 사용할 수 있지만 JSON 객체 내에서 트래버스합니다 (여기를 참조하십시오 : https://github.com/agershun/alasql/wiki/Search) – agershun
열려고하면 plunkr xlsx 파일에 문제가 있습니다. 그것. – crh225