Export MySQL query to Excel file: Difference between revisions

Jump to navigation Jump to search
m
Line 1: Line 1:
Export MySQL query to Excel file (XLS or XLSX file)
Export MySQL query to Excel file (XLS or XLSX file)


== Methods ==
== Microsoft Excel (XLS or XLSX) file limits ==
=== One step conversion: ex MySQL query -> Excel file ===
Methods of exporting MySQL query -> XLS/XLSX file
* [https://phpexcel.codeplex.com/ PHPExcel]
* other MySQL client softwares e.g. [https://www.quest.com/products/toad-for-mysql/ Toad for MySQL], ''$'' [https://www.navicat.com/cht Navicat GUI]
 
Notice the limit of Excel XLS file format:
# "Total number of characters that a cell can contain: 32,767 characters"
#* Using [http://www.w3resource.com/mysql/string-functions/mysql-substring-function.php MySQL SUBSTRING() function] ex: {{kbd | key = <nowiki>SUBSTRING(string_column, 1, 32767)</nowiki>}} for EXCEL 97<ref>[https://support.microsoft.com/en-us/kb/296053 Summary of capability limitations in Excel 97]</ref>-2007<ref>[https://support.office.com/en-us/article/Excel-specifications-and-limits-16c69c74-3d6a-4aaf-ba35-e6eb276e8eaa?CorrelationId=1de7e8d2-91e2-4eec-8868-4dc8cbd23463&ui=en-US&rs=en-US&ad=US Excel specifications and limits]</ref> (XLS 檔)
#* validate the count of characters: MySQL {{kbd | key = <nowiki>CHAR_LENGTH</nowiki>}} or Excel {{kbd | key = <nowiki>LEN</nowiki>}} functions
# "Length of formula contents: 8,192 characters" If the content start with the symbol {{kbd | key =<nowiki>=</nowiki>}} or {{kbd | key =<nowiki>-</nowiki>}}, Excel will consider the content is formula.
#* Using CONCAT {{kbd | key =<nowiki>'</nowiki>}} symbol ex: {{kbd | key = <nowiki>CONCAT('\'', string_column)</nowiki>}} If the content is not formula.
# "Worksheet size: 1,048,576 rows":
#* Using {{kbd | key =LIMIT 1048576}} for EXCEL 2007
 
<table border="1">
<table border="1">
  <tr>
  <tr>
Line 34: Line 20:
</table>
</table>


== Methods ==
=== One step conversion: ex MySQL query -> Excel file ===
Methods of exporting MySQL query -> XLS/XLSX file
* [https://phpexcel.codeplex.com/ PHPExcel]
* other MySQL client softwares e.g. [https://www.quest.com/products/toad-for-mysql/ Toad for MySQL], ''$'' [https://www.navicat.com/cht Navicat GUI]
Notice the limit of Excel XLS file format:
# "Total number of characters that a cell can contain: 32,767 characters"
#* Using [http://www.w3resource.com/mysql/string-functions/mysql-substring-function.php MySQL SUBSTRING() function] ex: {{kbd | key = <nowiki>SUBSTRING(string_column, 1, 32767)</nowiki>}} for EXCEL 97<ref>[https://support.microsoft.com/en-us/kb/296053 Summary of capability limitations in Excel 97]</ref>-2007<ref>[https://support.office.com/en-us/article/Excel-specifications-and-limits-16c69c74-3d6a-4aaf-ba35-e6eb276e8eaa?CorrelationId=1de7e8d2-91e2-4eec-8868-4dc8cbd23463&ui=en-US&rs=en-US&ad=US Excel specifications and limits]</ref> (XLS 檔)
#* validate the count of characters: MySQL {{kbd | key = <nowiki>CHAR_LENGTH</nowiki>}} or Excel {{kbd | key = <nowiki>LEN</nowiki>}} functions
# "Length of formula contents: 8,192 characters" If the content start with the symbol {{kbd | key =<nowiki>=</nowiki>}} or {{kbd | key =<nowiki>-</nowiki>}}, Excel will consider the content is formula.
#* Using CONCAT {{kbd | key =<nowiki>'</nowiki>}} symbol ex: {{kbd | key = <nowiki>CONCAT('\'', string_column)</nowiki>}} If the content is not formula.
# "Worksheet size: 1,048,576 rows":
#* Using {{kbd | key =LIMIT 1048576}} for EXCEL 2007


integrated solution for Excel limit 1 ~ limit 3
integrated solution for Excel limit 1 ~ limit 3

Navigation menu