亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

AngularJS:如何將選定的表格行復制到剪貼板?

AngularJS:如何將選定的表格行復制到剪貼板?

慕虎7371278 2022-12-29 13:59:20
我創建了一個表,其中有一個選項可以通過復選框選擇行,效果很好?,F在我正在尋找一些東西——想法、例子、類似的案例——來幫助我將那些選定的行復制到剪貼板,以便將它們一個接一個地粘貼到 Excel 文件中。checked我可以通過控制器中的屬性或通過 AngularJS 的filter功能過濾所有項目列表。我的表:<button ng-click="copySelected()" type="button">Copy selected to clipboard</button><table><thead>    <tr>        <th><input type="checkbox" ng-model="selectAll" ng-change="toggleAll()"></th>        <th>ID</th>        <th>Date</th>        <th>Subject</th>    </tr></thead><tbody ng-repeat="item in items">    <tr>        <td><input type="checkbox" id="chk-{{item.id}}" ng-model="options[$index]" ng-value="item.id"                 ng-change="toggleItem($index)"></td>        <td>{{item.id}}</td>        <td>{{item.issueDate}}</td>        <td>{{item.subject}}</td>    </tr></tbody></table>AngularJS 控制器:$scope.selectAll = false;$scope.options = [];$scope.toggleItem = function(index) {   $scope.items[index].checked = !$scope.items[index].checked;   if (!$scope.items[index].checked) {      $scope.selectAll = false;   }};  $scope.toggleAll = function() {   var checked = $scope.selectAll;   for (var i = 0; i < $scope.items.length; i++) {     $scope.options[i] = checked;     $scope.items[i].checked = checked;   }};// this is where I don't know how to progress from$scope.copySelected = function() {        if ($scope.selectAll) {            } else {        for (var i = 0; i < $scope.items.length; i++) {            if ($scope.items[i].checked) {                            }        }    }};
查看完整描述

1 回答

?
慕碼人2483693

TA貢獻1860條經驗 獲得超9個贊

一種可能性是以CSV格式轉換所選項目數組。然后你可以使用瀏覽器剪貼板 api將 csv 有效負載寫入剪貼板。

當我在 Libreoffice 中執行此操作時,應用程序會提示我在復制和粘貼到工作簿時導入文本格式。在 Excel 中,這可能需要一些調整,甚至需要用戶格式化數據。

  • 您也可以只使用SheetJs生成一個 Excel 文件——但對于您的用例來說可能會顯得臃腫。

  • 您可以將生成的 CSV 直接發送到瀏覽器。

剪貼板 api 在 IE 中不可用。


查看完整回答
反對 回復 2022-12-29
  • 1 回答
  • 0 關注
  • 155 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號