angularjs와 노드를 사용하여 인벤토리를 관리하는 애플리케이션을 만들었습니다. 이제 특정 화면에 내보내기 기능을 추가하고 싶습니다. 데이터를 Microsoft Excel 대신 새 Google 스프레드 시트로 내보내고 싶지만 방법을 찾을 수 없습니다.
내 데이터를 간단한 html 테이블로 변환하고 xls 파일을 다운로드하여 관리했지만 인코딩, 셀에 이미지 표시 등 많은 문제가 있으므로 실제로는 Google 스프레드 시트로 내보내고 싶습니다.
누구든지 html 테이블을 Google 스프레드 시트로 내보내는 간단한 방법에 대해 알고 있습니까? 불가능하다고 믿지 않는다 ...
감사
Finally, I found a simple (and actually very effective) solution around this issue.
I'm using ZeroClipboard to copy the table into the user's clipboard, then I'm opening a new Google Speardsheet. All the user needs to do is to click Ctrl-V and paste the table.
Here is the code:
HTML
<a ng-repeat="exportBtn in exportTables" class="btn btn-default" href="" clip-copy="getHtmlToCopy(exportBtn.target)" clip-copy-mime-type="text/plain">Copy {{exportBtn.name}} </a> <a class="btn btn-default" ng-href="http://spreadsheets.google.com/ccc?new&hl=he" target="_blank">open a new Google Spreadsheet</a>
JS
$rootScope.getHtmlToCopy = function (target) { var copyConst = {rowSeperator: "\r\n", colSeperator: "\t"} function $chk(obj) { return !!(obj || obj === 0) } var TableUtil = { nodeToString: function (table, rowSeperator, colSeperator) { var d = ""; if (table.childNodes.length) { if ("TD" == table.nodeName || "TH" == table.nodeName)colSeperator = rowSeperator = ""; for (table = table.firstChild; table;) { d += TableUtil.nodeToString(table, rowSeperator, colSeperator); if ("TR" == table.nodeName)d += rowSeperator; else if ("TD" == table.nodeName || "TH" == table.nodeName)d += colSeperator; table = table.nextSibling } } else"#text" == table.nodeName && $chk(table.nodeValue) && "" !== table.nodeValue && (rowSeperator = table.nodeValue, colSeperator = RegExp("\\t", "g"), rowSeperator = rowSeperator.replace(RegExp("\\n", "g"), ""), rowSeperator = rowSeperator.replace(colSeperator, ""), d += rowSeperator.trim()); return d } } var res = TableUtil.nodeToString($('table#' + target)[0], copyConst.rowSeperator, copyConst.colSeperator) console.log('got html to copy', res); //the following line might cause a popup blocker to stop the new tab. you can show a button after the copy is finished that will open a new tab window.open("http://spreadsheets.google.com/ccc?new"); return (res); }
Its ugly but its working perfectly!
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다