酒店预订平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 19 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. tableExport.jquery.plugin
  2. =========================
  3. <h3>Export HTML Table to</h3>
  4. <ul>
  5. <li> CSV
  6. <li> DOC
  7. <li> JSON
  8. <li> PDF
  9. <li> PNG
  10. <li> SQL
  11. <li> TSV
  12. <li> TXT
  13. <li> XLS (Excel 2000 HTML format)
  14. <li> XLSX (Excel 2007 Office Open XML format)
  15. <li> XML (Excel 2003 XML Spreadsheet format)
  16. <li> XML (Raw xml)
  17. </ul>
  18. Installation
  19. ============
  20. To save the generated export files on client side, include in your html code:
  21. ```html
  22. <script type="text/javascript" src="libs/FileSaver/FileSaver.min.js"></script>
  23. ```
  24. To export the table in XLSX (Excel 2007+ XML Format) format, you need to include additionally:
  25. ```html
  26. <script type="text/javascript" src="libs/js-xlsx/xlsx.core.min.js"></script>
  27. ```
  28. To export an html table to a PDF file, you can use jsPDF-AutoTable as a PDF producer:
  29. ```html
  30. <script type="text/javascript" src="libs/jsPDF/jspdf.min.js"></script>
  31. <script type="text/javascript" src="libs/jsPDF-AutoTable/jspdf.plugin.autotable.js"></script>
  32. ```
  33. Many HTML stylings can be converted to PDF with jsPDF, but support for non-western character sets is almost non-existent. Especially if you want to export Arabic or Chinese characters to your PDF file, you can use pdfmake as an alternative PDF producer. The disadvantage compared to jspdf is that using pdfmake has a reduced styling capability. To use pdfmake enable the pdfmake option and instead of the jsPDF files include
  34. ```html
  35. <script type="text/javascript" src="libs/pdfmake/pdfmake.min.js"></script>
  36. <script type="text/javascript" src="libs/pdfmake/vfs_fonts.js"></script>
  37. <!-- To export arabic characters include mirza_fonts.js _instead_ of vfs_fonts.js
  38. <script type="text/javascript" src="libs/pdfmake/mirza_fonts.js"></script>
  39. -->
  40. <!-- For a chinese font include either gbsn00lp_fonts.js or ZCOOLXiaoWei_fonts.js _instead_ of vfs_fonts.js
  41. <script type="text/javascript" src="libs/pdfmake/gbsn00lp_fonts.js"></script>
  42. -->
  43. ```
  44. To export the table in PNG format, you need to include:
  45. ```html
  46. <!-- For IE support include es6-promise before html2canvas -->
  47. <script type="text/javascript" src="libs/es6-promise/es6-promise.auto.min.js"></script>
  48. <script type="text/javascript" src="libs/html2canvas/html2canvas.min.js"></script>
  49. ```
  50. Regardless of the desired format, finally include:
  51. ```html
  52. <script type="text/javascript" src="tableExport.min.js"></script>
  53. ```
  54. Please keep this include order.
  55. Dependencies
  56. ============
  57. Library | Version
  58. --------|--------
  59. [jQuery](https://github.com/jquery/jquery) | \>= 1.9.1
  60. [es6-promise](https://github.com/stefanpenner/es6-promise) | \>= 4.2.4
  61. [FileSaver](https://github.com/hhurz/tableExport.jquery.plugin/blob/master/libs/FileSaver/FileSaver.min.js) | \>= 1.2.0
  62. [html2canvas](https://github.com/niklasvh/html2canvas) | \>= 0.5.0-beta4
  63. [jsPDF](https://github.com/MrRio/jsPDF) | \>=1.3.4
  64. [jsPDF-AutoTable](https://github.com/simonbengtsson/jsPDF-AutoTable) | 2.0.14 or 2.0.17
  65. [pdfmake](https://github.com/bpampuch/pdfmake) | 0.1.65
  66. [SheetJS](https://github.com/SheetJS/js-xlsx) | \>= 0.12.5
  67. Examples
  68. ========
  69. ```
  70. // CSV format
  71. $('#tableID').tableExport({type:'csv'});
  72. ```
  73. ```
  74. // Excel 2000 html format
  75. $('#tableID').tableExport({type:'excel'});
  76. ```
  77. ```
  78. // XML Spreadsheet 2003 file format with multiple worksheet support
  79. $('table').tableExport({type:'excel',
  80. mso: {fileFormat:'xmlss',
  81. worksheetName: ['Table 1','Table 2', 'Table 3']}});
  82. ```
  83. ```
  84. // PDF export using jsPDF only
  85. $('#tableID').tableExport({type:'pdf',
  86. jspdf: {orientation: 'p',
  87. margins: {left:20, top:10},
  88. autotable: false}
  89. });
  90. ```
  91. ```
  92. // PDF format using jsPDF and jsPDF Autotable
  93. $('#tableID').tableExport({type:'pdf',
  94. jspdf: {orientation: 'l',
  95. format: 'a3',
  96. margins: {left:10, right:10, top:20, bottom:20},
  97. autotable: {styles: {fillColor: 'inherit',
  98. textColor: 'inherit'},
  99. tableWidth: 'auto'}
  100. }
  101. });
  102. ```
  103. ```
  104. // PDF format with callback example
  105. function DoCellData(cell, row, col, data) {}
  106. function DoBeforeAutotable(table, headers, rows, AutotableSettings) {}
  107. $('table').tableExport({fileName: sFileName,
  108. type: 'pdf',
  109. jspdf: {format: 'bestfit',
  110. margins: {left:20, right:10, top:20, bottom:20},
  111. autotable: {styles: {overflow: 'linebreak'},
  112. tableWidth: 'wrap',
  113. tableExport: {onBeforeAutotable: DoBeforeAutotable,
  114. onCellData: DoCellData}}}
  115. });
  116. ```
  117. ```
  118. // PDF export using pdfmake
  119. $('#tableID').tableExport({type:'pdf',
  120. pdfmake:{enabled:true,
  121. docDefinition:{pageOrientation:'landscape'}}
  122. });
  123. ```
  124. Options (Default settings)
  125. =======
  126. ```
  127. csvEnclosure: '"'
  128. csvSeparator: ','
  129. csvUseBOM: true
  130. date: html: 'dd/mm/yyyy'
  131. displayTableName: false (Deprecated)
  132. escape: false (Deprecated)
  133. exportHiddenCells: false
  134. fileName: 'tableExport'
  135. htmlContent: false
  136. htmlHyperlink: 'content'
  137. ignoreColumn: []
  138. ignoreRow: []
  139. jsonScope: 'all'
  140. jspdf: orientation: 'p'
  141. unit:'pt'
  142. format: 'a4'
  143. margins: left: 20
  144. right: 10
  145. top: 10
  146. bottom: 10
  147. onDocCreated: null
  148. autotable: styles: cellPadding: 2
  149. rowHeight: 12
  150. fontSize: 8
  151. fillColor: 255
  152. textColor: 50
  153. fontStyle: 'normal'
  154. overflow: 'ellipsize'
  155. halign: 'inherit'
  156. valign: 'middle'
  157. headerStyles: fillColor: [52, 73, 94]
  158. textColor: 255
  159. fontStyle: 'bold'
  160. halign: 'inherit'
  161. valign: 'middle'
  162. alternateRowStyles: fillColor: 245
  163. tableExport: doc: null
  164. onAfterAutotable: null
  165. onBeforeAutotable: null
  166. onAutotableText: null
  167. onTable: null
  168. outputImages: true
  169. mso: fileFormat: 'xlshtml'
  170. onMsoNumberFormat: null
  171. pageFormat: 'a4'
  172. pageOrientation: 'portrait'
  173. rtl: false
  174. styles: []
  175. worksheetName: ''
  176. xslx: formatId: date: 14
  177. numbers: 2
  178. numbers: html: decimalMark: '.'
  179. thousandsSeparator: ','
  180. output: decimalMark: '.',
  181. thousandsSeparator: ','
  182. onAfterSaveToFile: null
  183. onBeforeSaveToFile: null
  184. onCellData: null
  185. onCellHtmlData: null
  186. onCellHtmlHyperlink: null
  187. onIgnoreRow: null
  188. onTableExportBegin: null
  189. onTableExportEnd: null
  190. outputMode: 'file'
  191. pdfmake: enabled: false
  192. docDefinition: pageSize: 'A4'
  193. pageOrientation: 'portrait'
  194. styles: header: background: '#34495E'
  195. color: '#FFFFFF'
  196. bold: true
  197. alignment: 'center'
  198. fillColor: '#34495E
  199. alternateRow: fillColor: '#f5f5f5'
  200. defaultStyle: color: '#000000'
  201. fontSize: 8
  202. font: 'Roboto'
  203. fonts: {}
  204. preserve: leadingWS: false
  205. trailingWS: false
  206. preventInjection: true
  207. sql: tableEnclosure: '`'
  208. columnEnclosure: '`'
  209. tbodySelector: 'tr'
  210. tfootSelector: 'tr'
  211. theadSelector: 'tr'
  212. tableName: 'myTableName'
  213. type: 'csv'
  214. ```
  215. ```ignoreColumn``` can be either an array of indexes (i.e. [0, 2]) or field names (i.e. ["id", "name"]).
  216. * Indexes correspond to the position of the header elements `th` in the DOM starting at 0. (If the `th` elements are removed or added to the DOM, the indexes will be shifted so use the functionality wisely!)
  217. * Field names should correspond to the values set on the "data-field" attribute of the header elements `th` in the DOM.
  218. * "Nameless" columns without data-field attribute will be named by their index number (converted to a string)
  219. To disable formatting of numbers in the exported output, which can be useful for csv and excel format, set the option ``` numbers: output ``` to ``` false ```.
  220. Set the option ``` mso.fileFormat ``` to ``` 'xmlss' ``` if you want to export in XML Spreadsheet 2003 file format. Use this format if multiple tables should be exported into a single file.
  221. Excel 2000 html format is the default excel file format which has better support of exporting table styles.
  222. The ``` mso.styles ``` option lets you define the css attributes of the original html table cells, that should be taken over when exporting to an excel worksheet (Excel 2000 html format only).
  223. To export in XSLX format [SheetJS/js-xlsx](https://github.com/SheetJS/js-xlsx) is used. Please note that the implementation of this format type lets you only export table data, but not any styling information of the html table.
  224. Note: There is an option ``` preventInjection ``` (default is enabled) that prevents formula injection when exporting in CSV or Excel format. To achieve that a single quote will be prepended to cell strings that start with =,+,- or @
  225. For jspdf options see the documentation of [jsPDF](https://github.com/MrRio/jsPDF) and [jsPDF-AutoTable](https://github.com/simonbengtsson/jsPDF-AutoTable) resp.
  226. There is an extended setting for ``` jsPDF option 'format' ```. Setting the option value to ``` 'bestfit' ``` lets the tableExport plugin try to choose the minimum required paper format and orientation in which the table (or tables in multitable mode) completely fits without column adjustment.
  227. Also there is an extended setting for the ``` jsPDF-AutoTable options 'fillColor', 'textColor' and 'fontStyle'```. When setting these option values to ``` 'inherit' ``` the original css values for background and text color will be used as fill and text color while exporting to pdf. A css font-weight >= 700 results in a bold fontStyle and the italic css font-style will be used as italic fontStyle.
  228. When exporting to pdf the option ``` outputImages ``` lets you enable or disable the output of images that are located in the original html table.
  229. Optional html data attributes
  230. =============================
  231. (can be applied while generating the table that you want to export)
  232. <h4>data-tableexport-cellformat</h4>
  233. ```html
  234. <td data-tableexport-cellformat="">...</td> -> An empty data value preserves format of cell content. E.g. no number seperator conversion
  235. More cell formats to be come...
  236. ```
  237. <h4>data-tableexport-colspan</h4>
  238. ```html
  239. <td colspan="2" data-tableexport-colspan="3">...</td> -> Overwrites the colspan attribute of the table cell during export.
  240. This attribute can be used if there follow hidden cells, that will be exported by using the "data-tableexport-display" attribute.
  241. ```
  242. <h4>data-tableexport-display</h4>
  243. ```html
  244. <table style="display:none;" data-tableexport-display="always">...</table> -> A hidden table will be exported
  245. <td style="display:none;" data-tableexport-display="always">...</td> -> A hidden cell will be exported
  246. <td data-tableexport-display="none">...</td> -> This cell will not be exported
  247. <tr data-tableexport-display="none">...</tr> -> All cells of this row will not be exported
  248. ```
  249. <h4>data-tableexport-msonumberformat</h4>
  250. ```html
  251. <td data-tableexport-msonumberformat="\@">...</td> -> Data value will be used to style excel cells with mso-number-format (Excel 2000 html format only)
  252. Format Description
  253. ===================================================================================
  254. "\@" Excel treats cell content always as text, even numbers
  255. "0" Excel will display no decimals for numbers
  256. "0\.000" Excel displays numbers with 3 decimals
  257. "0%" Excel will display a number as percent with no decimals
  258. "Percent" Excel will display a number as percent with 2 decimals
  259. "\#\,\#\#0\.000" Comma with 3 decimals
  260. "mm\/dd\/yy" Date7
  261. "mmmm\ d\,\ yyyy" Date9
  262. "m\/d\/yy\ h\:mm\ AM\/PM" D -T AMPM
  263. "Short Date" 01/03/1998
  264. "Medium Date" 01-mar-98
  265. "d\-mmm\-yyyy" 01-mar-1998
  266. "Short Time" 5:16
  267. "Medium Time" 5:16 am
  268. "Long Time" 5:16:21:00
  269. "0\.E+00" Scientific Notation
  270. "\#\ ???\/???" Fractions - up to 3 digits
  271. "\0022£\0022\#\,\#\#0\.00" £12.76
  272. "\#\,\#\#0\.00_ \;\[Red\]\-\#\,\#\#0\.00\ " 2 decimals, negative red numbers
  273. ```
  274. <h4>data-tableexport-rowspan</h4>
  275. ```html
  276. <td rowspan="2" data-tableexport-rowspan="3">...</td> -> Overwrites the rowspan attribute of the table cell during export.
  277. This attribute can be used if there follow hidden rows, that will be exported by using the "data-tableexport-display" attribute.
  278. ```
  279. <h4>data-tableexport-value</h4>
  280. ```html
  281. <th data-tableexport-value="export title">title</th> -> "export title" instead of "title" will be exported
  282. <td data-tableexport-value="export content">content</td> -> "export content" instead of "content" will be exported
  283. ```
  284. <h4>data-tableexport-xlsxformatid</h4>
  285. ```html
  286. <td data-tableexport-xlsxformatid="14">...</td> -> The data value represents a format id that will be used to format the content of a cell in Excel. This data attribute overwrites the default setting of defaults.mso.xslx.formatId.
  287. This attribute is for Excel 2007 Office Open XML format only.
  288. Format id Description
  289. ===============================================
  290. "1" 0
  291. "2" 0.00
  292. "3" #,##0
  293. "4" #,##0.00
  294. "9" 0%
  295. "10" 0.00%
  296. "11" 0.00E+00
  297. "12" # ?/?
  298. "13" # ??/??
  299. "14" m/d/yy (will be localized by Excel)
  300. "15" d-mmm-yy
  301. "16" d-mmm
  302. "17" mmm-yy
  303. "18" h:mm AM/PM
  304. "19" h:mm:ss AM/PM
  305. "20" h:mm
  306. "21" h:mm:ss
  307. "22" m/d/yy h:mm
  308. "37" #,##0 ;(#,##0)
  309. "38" #,##0 ;[Red](#,##0)
  310. "39" #,##0.00;(#,##0.00)
  311. "40" #,##0.00;[Red](#,##0.00)
  312. "45" mm:ss
  313. "46" [h]:mm:ss
  314. "47" mmss.0
  315. "48" ##0.0E+0
  316. "49" @
  317. "56" 上午/下午 hh時mm分ss秒
  318. ```
  319. Excel Notes
  320. ===========
  321. When exporting in Excel 2000 html format (xlshtml) the default extension of the result file is XLS although the type of the file content is HTML. When you open a file in Microsoft Office Excel 2007 or later that contains content that does not match the files extension, you receive the following warning message:
  322. ```The file you are trying to open, 'name.ext', is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?```
  323. According to this [Knowledge base article](https://support.microsoft.com/en-us/help/948615/error-opening-file-the-file-format-differs-from-the-format-that-the-fi) The warning message can help prevent unexpected problems that might occur because of possible incompatibility between the actual content of the file and the file name extension. The article also gives you some hints to disable the warning message.