{"id":22575,"date":"2022-12-26T07:02:00","date_gmt":"2022-12-26T06:02:00","guid":{"rendered":"https:\/\/expert-only.com\/?p=22575"},"modified":"2023-02-16T15:02:09","modified_gmt":"2023-02-16T14:02:09","slug":"export-sql-server-table-to-excel-python","status":"publish","type":"post","link":"https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/","title":{"rendered":"Export SQL Server table to Excel in Python"},"content":{"rendered":"\n<h4 class=\"has-text-align-center wp-block-heading\"><strong><em>How to export a SQL Server table to an Excel file in Python ?<\/em><\/strong><\/h4>\n\n\n\n<p>In this tutorial, we will learn how to export a SQL Server table to an Excel file in Python. We will go through two main steps: creating a sample table in SQL Server, using SSMS or directl in Python, preparing an empty Excel file with formatting, and exporting the content of the table to the file in Excel. We will be using the openpyxl and pyodbc libraries in Python for this task. By the end of this tutorial, you will have a clear understanding of how to export data from a SQL Server database to an Excel file using Python.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-1-create-a-sample-sql-server-table\">1. Create a sample SQL Server table <\/h2>\n\n\n\n<p>To demonstrate how to export a SQL Server table to an Excel file in Python, we first need a sample table in our SQL Server database.<\/p>\n\n\n\n<p>For this, we can use the following SQL script to create a simple table named <strong><em>employees<\/em><\/strong> with four columns:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>id<\/li>\n\n\n\n<li>name<\/li>\n\n\n\n<li>department<\/li>\n\n\n\n<li>salary<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">1.1 Code to create the sample table using SSMS<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">CREATE TABLE employees (\n   id INT PRIMARY KEY,\n   name VARCHAR(50),\n   department VARCHAR(50),\n   salary INT\n);\n\nINSERT INTO employees VALUES (1, 'John Smith', 'Sales', 50000);\nINSERT INTO employees VALUES (2, 'Jane Doe', 'Marketing', 60000);\nINSERT INTO employees VALUES (3, 'Bob Johnson', 'IT', 70000);\nINSERT INTO employees VALUES (4, 'Alice Wong', 'HR', 55000);\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">1.2 Code to create the table directly with Python<\/h3>\n\n\n\n<p>Of course it is also possible to create the table directly from Python. To do so, you can use the <strong><em>pyodbc<\/em><\/strong> library in Python to connect to your SQL Server database and execute SQL queries. Here&#8217;s an example code that creates the &#8220;employees&#8221; table and inserts the four rows directly from Python code:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import pyodbc\n\n# connect to the SQL Server database\nconnection = pyodbc.connect('Driver={SQL Server};'\n                            'Server=localhost;'\n                            'Database=Expert-Only;'\n                            'Trusted_Connection=yes;')\n\n# create the employees table\ncursor = connection.cursor()\ncursor.execute(\"\"\"\n    CREATE TABLE employees (\n        id INT PRIMARY KEY,\n        name VARCHAR(50),\n        department VARCHAR(50),\n        salary INT\n    )\n\"\"\")\n\n# insert the rows into the employees table\ncursor.execute(\"INSERT INTO employees VALUES (1, 'John Smith', 'Sales', 50000)\")\ncursor.execute(\"INSERT INTO employees VALUES (2, 'Jane Doe', 'Marketing', 60000)\")\ncursor.execute(\"INSERT INTO employees VALUES (3, 'Bob Johnson', 'IT', 70000)\")\ncursor.execute(\"INSERT INTO employees VALUES (4, 'Alice Wong', 'HR', 55000)\")\n\n# commit the changes and close the connection\nconnection.commit()\nconnection.close()\n<\/pre>\n\n\n\n<p>To learn more on <a href=\"https:\/\/expert-only.com\/en\/python\/work-with-sql-server-using-python\/\">how to manage SQL Server tables in Python<\/a>, read this tutorial.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-sql-and-it-tutorials wp-block-embed-sql-and-it-tutorials\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"SRazqa5dsh\"><a href=\"https:\/\/expert-only.com\/en\/python\/work-with-sql-server-using-python\/\">Work with SQL Server using Python and pyodbc<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Work with SQL Server using Python and pyodbc&#8221; &#8212; SQL and IT Tutorials\" src=\"https:\/\/expert-only.com\/en\/python\/work-with-sql-server-using-python\/embed\/#?secret=me8I69kKl9#?secret=SRazqa5dsh\" data-secret=\"SRazqa5dsh\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">2. Prepare the Excel file format and export the SQL Server table<\/h2>\n\n\n\n<p>Before we can export our SQL Server table to an Excel file in Python, we need to prepare an empty Excel file and format it according to our needs. For this, we can use the <a href=\"https:\/\/openpyxl.readthedocs.io\/en\/stable\/\" target=\"_blank\" rel=\"noreferrer noopener\">openpyxl<\/a> library in Python. The  example code that follows creates a new Excel file and formats its header row.<\/p>\n\n\n\n<p>With our SQL Server table and Excel file ready, we can now export the content of the former to the latter. For this, we can use the <strong><em>pyodbc<\/em><\/strong> library to connect to our SQL Server database and retrieve the data, and then the <strong><em>openpyxl<\/em><\/strong> library again to populate the rows in the Excel file. Here&#8217;s an example code that performs this tasks, i.e. configure the Excel formatting and export data into the file.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import openpyxl\nimport pyodbc\n\n# create a new workbook and select the active worksheet\nworkbook = openpyxl.Workbook()\nworksheet = workbook.active\n\n# set the column headers and format them\nheaders = [\"ID\", \"Name\", \"Department\", \"Salary\"]\nfor col, header in enumerate(headers, start=1):\n    cell = worksheet.cell(row=1, column=col)\n    cell.value = header\n    cell.font = openpyxl.styles.Font(bold=True)\n    cell.alignment = openpyxl.styles.Alignment(horizontal=\"center\")\n\n# connect to the SQL Server database\nconnection = pyodbc.connect('Driver={SQL Server};'\n                            'Server=localhost;'\n                            'Database=Expert-Only;'\n                            'Trusted_Connection=yes;')\n\n# retrieve the data from the employees table\ncursor = connection.cursor()\ncursor.execute(\"SELECT id, name, department, salary FROM employees\")\ndata = cursor.fetchall()\n\n# populate the rows in the Excel file\nfor row, record in enumerate(data, start=2):\n    for col, value in enumerate(record, start=1):\n        cell = worksheet.cell(row=row, column=col)\n        cell.value = value\n\n# save the Excel file\nworkbook.save(\"C:\\data\\employees.xlsx\")\n<\/pre>\n\n\n\n<p>In this code, we first connect to our SQL Server database using the &#8220;pyodbc&#8221; library. And then execute a SQL query to retrieve all the rows from the &#8220;employees&#8221; table. We then use a nested loop to populate the rows in the Excel file. And finally save the file with the &#8220;save&#8221; method.<\/p>\n\n\n\n<p>The result is the <strong><em>employees.xlsx<\/em><\/strong> Excel file exported to the <strong>C:\\Data\\<\/strong> folder with the headers in bold and the 4 lines of data as in the source table.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"780\" height=\"540\" src=\"https:\/\/expert-only.com\/wp-content\/uploads\/2023\/02\/python-export-sq-server-table-into-excel.jpg\" alt=\"Export a SQL Server table content to an Excel file using a Python script and the openpyxl module\" class=\"wp-image-22604\" srcset=\"https:\/\/expert-only.com\/wp-content\/uploads\/2023\/02\/python-export-sq-server-table-into-excel.jpg 780w, https:\/\/expert-only.com\/wp-content\/uploads\/2023\/02\/python-export-sq-server-table-into-excel-300x208.jpg 300w, https:\/\/expert-only.com\/wp-content\/uploads\/2023\/02\/python-export-sq-server-table-into-excel-768x532.jpg 768w\" sizes=\"auto, (max-width: 780px) 100vw, 780px\" \/><figcaption class=\"wp-element-caption\"><strong><em>Export a SQL Server table content to an Excel file using a Python script and the openpyxl module<\/em><\/strong><\/figcaption><\/figure><\/div>\n\n\n<p>And that&#8217;s it! With these three steps, we can export SQL Server data into an MS Excel document in Python.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Conclusion on SQL Server table export into Excel in Python<\/h2>\n\n\n\n<p>You have successfully learned how to export a SQL Server table to an Excel file in Python. By following the three steps outlined in this tutorial, you can now connect to your MS SQL database. Then retrieve data from a table, and export it to an Excel file with proper formatting using Python. This skill can be useful for a wide range of data analysis and reporting tasks. Continue to explore and practice with these libraries and tools to enhance your Python data manipulation skills.<\/p>\n\n\n\n<p>To go further, this time on file management and compression, this tutorial shows <a href=\"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/\">how to zip and unzip files into archives using the zipfile python module<\/a>. <\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-sql-and-it-tutorials wp-block-embed-sql-and-it-tutorials\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"ZRuH7DYTh9\"><a href=\"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/\">How to zip and unzip files with the Python zipfile  module ?<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;How to zip and unzip files with the Python zipfile  module ?&#8221; &#8212; SQL and IT Tutorials\" src=\"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/embed\/#?secret=qxwWFiNZSs#?secret=ZRuH7DYTh9\" data-secret=\"ZRuH7DYTh9\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>How to export a SQL Server table to an Excel file in Python ? In this tutorial, we will learn how to export a SQL Server table to an Excel file in Python. We will go through two main <a class=\"mh-excerpt-more\" href=\"https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/\" title=\"Export SQL Server table to Excel in Python\">&#8230;<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":10699,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[657],"tags":[],"class_list":{"0":"post-22575","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-python"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.7 (Yoast SEO v26.2) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Export SQL Server table to Excel in Python - openpyxl tutorial<\/title>\n<meta name=\"description\" content=\"How to export a SQL Server table to an Excel file in Python ? In this tutorial, we use the openpyxl and the pyodbc Python modules.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Export SQL Server table to Excel in Python\" \/>\n<meta property=\"og:description\" content=\"How to export a SQL Server table to an Excel file in Python ? In this tutorial, we use the openpyxl and the pyodbc Python modules.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL and IT Tutorials\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ExpertOnlyCom\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-12-26T06:02:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-02-16T14:02:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/idea-45DA743585A_1920x1080.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Expert-Only\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@expert_only\" \/>\n<meta name=\"twitter:site\" content=\"@expert_only\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Expert-Only\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/\"},\"author\":{\"name\":\"Expert-Only\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef\"},\"headline\":\"Export SQL Server table to Excel in Python\",\"datePublished\":\"2022-12-26T06:02:00+00:00\",\"dateModified\":\"2023-02-16T14:02:09+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/\"},\"wordCount\":655,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/expert-only.com\/en\/#organization\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/idea-45DA743585A_1920x1080.jpg\",\"articleSection\":[\"Python tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/\",\"url\":\"https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/\",\"name\":\"Export SQL Server table to Excel in Python - openpyxl tutorial\",\"isPartOf\":{\"@id\":\"https:\/\/expert-only.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/idea-45DA743585A_1920x1080.jpg\",\"datePublished\":\"2022-12-26T06:02:00+00:00\",\"dateModified\":\"2023-02-16T14:02:09+00:00\",\"description\":\"How to export a SQL Server table to an Excel file in Python ? In this tutorial, we use the openpyxl and the pyodbc Python modules.\",\"breadcrumb\":{\"@id\":\"https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/#primaryimage\",\"url\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/idea-45DA743585A_1920x1080.jpg\",\"contentUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/idea-45DA743585A_1920x1080.jpg\",\"width\":1920,\"height\":1080},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"en\",\"item\":\"https:\/\/expert-only.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Export SQL Server table to Excel in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/expert-only.com\/en\/#website\",\"url\":\"https:\/\/expert-only.com\/en\/\",\"name\":\"SQL and IT Tutorials\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/expert-only.com\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/expert-only.com\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/expert-only.com\/en\/#organization\",\"name\":\"Expert-Only\",\"url\":\"https:\/\/expert-only.com\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg\",\"contentUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg\",\"width\":381,\"height\":174,\"caption\":\"Expert-Only\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/ExpertOnlyCom\/\",\"https:\/\/x.com\/expert_only\",\"https:\/\/www.youtube.com\/channel\/UCMS5sR_FwAetB0FmciNvUaA\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef\",\"name\":\"Expert-Only\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g\",\"caption\":\"Expert-Only\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Export SQL Server table to Excel in Python - openpyxl tutorial","description":"How to export a SQL Server table to an Excel file in Python ? In this tutorial, we use the openpyxl and the pyodbc Python modules.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/","og_locale":"en_US","og_type":"article","og_title":"Export SQL Server table to Excel in Python","og_description":"How to export a SQL Server table to an Excel file in Python ? In this tutorial, we use the openpyxl and the pyodbc Python modules.","og_url":"https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/","og_site_name":"SQL and IT Tutorials","article_publisher":"https:\/\/www.facebook.com\/ExpertOnlyCom\/","article_published_time":"2022-12-26T06:02:00+00:00","article_modified_time":"2023-02-16T14:02:09+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/idea-45DA743585A_1920x1080.jpg","type":"image\/jpeg"}],"author":"Expert-Only","twitter_card":"summary_large_image","twitter_creator":"@expert_only","twitter_site":"@expert_only","twitter_misc":{"Written by":"Expert-Only","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/#article","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/"},"author":{"name":"Expert-Only","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef"},"headline":"Export SQL Server table to Excel in Python","datePublished":"2022-12-26T06:02:00+00:00","dateModified":"2023-02-16T14:02:09+00:00","mainEntityOfPage":{"@id":"https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/"},"wordCount":655,"commentCount":0,"publisher":{"@id":"https:\/\/expert-only.com\/en\/#organization"},"image":{"@id":"https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/idea-45DA743585A_1920x1080.jpg","articleSection":["Python tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/","url":"https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/","name":"Export SQL Server table to Excel in Python - openpyxl tutorial","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/#primaryimage"},"image":{"@id":"https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/idea-45DA743585A_1920x1080.jpg","datePublished":"2022-12-26T06:02:00+00:00","dateModified":"2023-02-16T14:02:09+00:00","description":"How to export a SQL Server table to an Excel file in Python ? In this tutorial, we use the openpyxl and the pyodbc Python modules.","breadcrumb":{"@id":"https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/#primaryimage","url":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/idea-45DA743585A_1920x1080.jpg","contentUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/idea-45DA743585A_1920x1080.jpg","width":1920,"height":1080},{"@type":"BreadcrumbList","@id":"https:\/\/expert-only.com\/en\/python\/export-sql-server-table-to-excel-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"en","item":"https:\/\/expert-only.com\/en\/"},{"@type":"ListItem","position":2,"name":"Export SQL Server table to Excel in Python"}]},{"@type":"WebSite","@id":"https:\/\/expert-only.com\/en\/#website","url":"https:\/\/expert-only.com\/en\/","name":"SQL and IT Tutorials","description":"","publisher":{"@id":"https:\/\/expert-only.com\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/expert-only.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/expert-only.com\/en\/#organization","name":"Expert-Only","url":"https:\/\/expert-only.com\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/","url":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg","contentUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg","width":381,"height":174,"caption":"Expert-Only"},"image":{"@id":"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/ExpertOnlyCom\/","https:\/\/x.com\/expert_only","https:\/\/www.youtube.com\/channel\/UCMS5sR_FwAetB0FmciNvUaA"]},{"@type":"Person","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef","name":"Expert-Only","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g","caption":"Expert-Only"}}]}},"_links":{"self":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/22575","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/comments?post=22575"}],"version-history":[{"count":0,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/22575\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media\/10699"}],"wp:attachment":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media?parent=22575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/categories?post=22575"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/tags?post=22575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}