kinldy讓我知道添加CSV導出按鈕,並在magento2定製網格創建CSV。我創建了一個網格和表單。需要在magento2中添加csv導出功能。Magento2定製網格導出CSV
2
A
回答
0
添加CSV文件導出按鈕,網格塊佈局(XML):
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="your.grid.container">
<block class="Yourpackage\Yourmodule\Block\Adminhtml\Sample\Grid" name="sample.grid" as="grid">
<!-- Arguments or blocks -->
<!-- Export Widget -->
<block class="Magento\Backend\Block\Widget\Grid\Export" name="sample.grid.export" as="grid.export">
<arguments>
<argument name="exportTypes" xsi:type="array">
<item name="csv" xsi:type="array">
<item name="urlPath" xsi:type="string">*/*/exportCsv</item>
<item name="label" xsi:type="string" translate="true">CSV</item>
</item>
</argument>
</arguments>
</block>
<!-- Columns block -->
</block>
</referenceBlock>
</body>
</page>
創建你的控制器:
<?php
namespace Yourpackage\Yourmodule\Controller\Adminhtml\Sample;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\App\Filesystem\DirectoryList;
class ExportCsv extends \Yourpackage\Yourmodule\Controller\Adminhtml\Sample
{
/**
* Export data grid to CSV format
*
* @return ResponseInterface
*/
public function execute()
{
$this->_view->loadLayout();
$fileName = 'sample_data.csv';
$content = $this->_view->getLayout()->getChildBlock('sample.grid', 'grid.export');
return $this->_fileFactory->create(
$fileName,
$content->getCsvFile($fileName),
DirectoryList::VAR_DIR
);
}
}
2
創建控制器
<?php
namespace Yourpackage\Yourmodule\Controller\Adminhtml\Sample;
class ExportCsv extends \Magento\Backend\App\Action
{
protected $_fileFactory;
protected $_response;
protected $_view;
protected $directory;
protected $converter;
protected $resultPageFactory ;
protected $directory_list;
public function __construct(\Magento\Backend\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory
) {
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context);
}
public function execute()
{
$fileName = 'yourfilename.csv';
$resultPage = $this->resultPageFactory ->create();
$content = $resultPage->getLayout()->getBlock('yourblockname')->getCsv();;
$this->_sendUploadResponse($fileName, $content);
}
protected function _sendUploadResponse($fileName, $content, $contentType='application/octet-stream') {
$this->_response->setHttpResponseCode(200)
->setHeader('Pragma', 'public', true)
->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)
->setHeader('Content-type', $contentType, true)
->setHeader('Content-Length', strlen($content), true)
->setHeader('Content-Disposition', 'attachment; filename="' . $fileName . '"', true)
->setHeader('Last-Modified', date('r'), true)
->setBody($content)
->sendResponse();
die;
}
}
創建佈局的xml yourmodule_yourcontroller_exportcsv
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="yourmodule_yourcontroller_grid"/>
</page>
+0
雖然我們開這樣的這樣的csv文件,它是要求「過濾器選擇」爲什麼這麼問它好嗎? –
+0
因爲對於第一次打開該文件時,它要求你列分開在此基礎上像逗號(,)或半柱(;)等。 –
0
要magento2使用UI組件做外銷電網
按照UI行列表組件XML<exportButton name="export_button">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="selectProvider" xsi:type="string">vendor_listing.vendor_listing.example_blog_columns.ids</item>
</item>
</argument>
</exportButton>
這將在magento2生成網格加載的集合CSV
在容器標籤的附加
相關問題
- 1. 將SDK2網格導出爲CSV
- 2. 以指定格式導出到csv
- 3. 以特定格式導出到csv
- 4. 導出wpf數據網格到自定義Excel CSV文件
- 5. PowerShell導出CSV格式
- 6. 導出CSV字段格式
- 7. Powershell導出CSV格式
- 8. jQuery表格到CSV導出
- 9. SSRS導出爲CSV格式
- 10. 將網格數據導出爲CSV和PDF格式
- 11. Telerik - 網格導出 - 大小限制
- 12. 以csv格式導出表格
- 13. 導軌 - CSV(導出爲csv)
- 14. 角度ui網格導出到CSV回調
- 15. 將dojo數據網格導出到csv文件
- 16. Silverlight Telerik RadGridView - 導出到csv並不顯示所有網格列
- 17. 將backgrid.js的網格數據導出爲csv
- 18. 從管理產品網格將產品導出到csv
- 19. 定製超出網格的模板
- 20. Python:從網頁抓取導出CSV
- 21. CSV導出使用API網關和Lambda
- 22. CSV數據導出/複製到HDFS將在怪異格式
- 23. YourKit導出CSV數據格式
- 24. 導出爲Python的CSV文件格式
- 25. PHP的MYSQL BLOB導出爲CSV格式
- 26. 將刮取的表格導出爲CSV
- 27. 將Crystal Report導出爲CSV格式
- 28. PHP日期導出爲CSV格式
- 29. 用php格式導出csv文件
- 30. 數據導出爲CSV格式
,我已經嘗試這樣做,越來越空了的print_r($內容)。不能讓佈局blocks.any建議 – user3040610
致命錯誤:調用上噓聲成員函數getCsvFile()瘦 – Naveenbos