2016-04-22 5 views
1

Jquery Datatablesライブラリを使用してテーブルデータから生成されるExcelのトップロー/ヘッダーファイルをフィルタリングすることを有効にしようとしています。jqueryデータテーブルを使用してexcelエクスポートでヘッダーフィルタを有効にする

私はこのチュートリアルhttps://datatables.net/extensions/buttons/examples/initialisation/export.htmlに従いました。それは素晴らしい作品で、以下のようなファイルを生成しました。

enter image description here

あなたがそのPICで見ることができるように、一番上の行へのフィルタがありません。私は、オープン後にExcelファイルでフィルタを有効にできることを知っています。しかし、私はExcelファイルが生成されるときにそれをしようとしています。

したがって、エクスポートされたExcelファイルは以下のようになります。

enter image description here

あなたはフィルターと赤い円の中にハイライトを見ることができます。

これは可能かどうか、それを達成する方法についてのご意見は高く評価されます。

ありがとうございます。

答えて

1

ファイルbuttons.html5.jsのExcelファイルスキーマを変更することで、フィルタを自動的に有効にすることができます。

buttons.html5.jsファイルには、次のコードがあります。

// Excel - Pre-defined strings to build a minimal XLSX file 
var excelStrings = { 
    "_rels/.rels": '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\ 
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">\ 
    <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/>\ 
</Relationships>', 

    "xl/_rels/workbook.xml.rels": '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\ 
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">\ 
    <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/>\ 
</Relationships>', 

    "[Content_Types].xml": '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\ 
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">\ 
    <Default Extension="xml" ContentType="application/xml"/>\ 
    <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>\ 
    <Default Extension="jpeg" ContentType="image/jpeg"/>\ 
    <Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/>\ 
    <Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>\ 
</Types>', 

    "xl/workbook.xml": '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\ 
<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">\ 
    <fileVersion appName="xl" lastEdited="5" lowestEdited="5" rupBuild="24816"/>\ 
    <workbookPr showInkAnnotation="0" autoCompressPictures="0"/>\ 
    <bookViews>\ 
     <workbookView xWindow="0" yWindow="0" windowWidth="25600" windowHeight="19020" tabRatio="500"/>\ 
    </bookViews>\ 
    <sheets>\ 
     <sheet name="__SHEET_NAME__" sheetId="1" r:id="rId1"/>\ 
    </sheets>\ 
</workbook>', 

    "xl/worksheets/sheet1.xml": '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\ 
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="x14ac" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac">\ 
    <sheetData>\ 
     __DATA__\ 
    </sheetData>\ 
</worksheet>' 
}; 

上記のオブジェクトを以下のように更新する必要があります。

excelStrings["xl/worksheets/sheet1.xml"] = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="x14ac" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"><sheetData>__DATA__</sheetData><autoFilter ref="A1:g1"/></worksheet>'; 

唯一の違いは、<autoFilter ref="A1:g1"/>を付加していることです。

ref = "A1:G1"は、この自動フィルタを有効にする列です。

これは私が自動フィルタを有効にするという問題を解決した方法です。

関連する問題