<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by lilacsol on Medium]]></title>
        <description><![CDATA[Stories by lilacsol on Medium]]></description>
        <link>https://medium.com/@lilacsol?source=rss-6bc48047d503------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by lilacsol on Medium</title>
            <link>https://medium.com/@lilacsol?source=rss-6bc48047d503------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 18:31:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lilacsol/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Python and Excel with Openpyxl — Sorting]]></title>
            <link>https://medium.com/@lilacsol/python-and-excel-with-openpyxl-sorting-14793e2e2339?source=rss-6bc48047d503------2</link>
            <guid isPermaLink="false">https://medium.com/p/14793e2e2339</guid>
            <category><![CDATA[openpyxl]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[excel]]></category>
            <dc:creator><![CDATA[lilacsol]]></dc:creator>
            <pubDate>Fri, 27 Feb 2026 00:29:39 GMT</pubDate>
            <atom:updated>2026-02-27T00:29:39.795Z</atom:updated>
            <content:encoded><![CDATA[<ol><li>Load workbook and worksheet</li><li>Iterate data from column A&amp;B and saved data in list</li><li>Sort the data list in reverse order</li></ol><pre>import openpyxl<br><br># Load workbook and worksheet<br>workbook = openpyxl.load_workbook(&quot;Chart.xlsx&quot;)<br>sheet = workbook.active<br><br># Iterate data in column A &amp; B and saved data in list<br>data_list= list(sheet.iter_rows(min_row=2, max_col=2, values_only=True))<br>print(data_list)<br><br># sort the value in reverse from data list<br># remove the reverse if to sort the data in order<br># key=lambda data_list:data_list[1] returns the second item from the list <br># as sort key<br>sorted_list = sorted(data_list,key=lambda data_list:data_list[1], reverse=True)<br>print(sorted_list)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4TgYtQPpyVFLQJCatWd22w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14793e2e2339" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python and Excel with Openpyxl — Create Graph]]></title>
            <link>https://medium.com/@lilacsol/python-and-excel-with-openpyxl-create-graph-f652793bee3b?source=rss-6bc48047d503------2</link>
            <guid isPermaLink="false">https://medium.com/p/f652793bee3b</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[openpyxl]]></category>
            <category><![CDATA[excel]]></category>
            <dc:creator><![CDATA[lilacsol]]></dc:creator>
            <pubDate>Sat, 21 Feb 2026 14:35:53 GMT</pubDate>
            <atom:updated>2026-02-27T00:30:46.441Z</atom:updated>
            <content:encoded><![CDATA[<h3>Create Column / Bar Graph</h3><ol><li>Create new workbook &amp; worksheet</li><li>Create data set in list</li><li>Add data to worksheet</li><li>Create new bar chart</li><li>Add data to bar chart</li><li>Add bar chart to worksheet</li><li>Save workbook</li></ol><pre>import openpyxl<br>from openpyxl.chart import BarChart, Reference<br><br># Create new workbook and worksheet<br>workbook = openpyxl.Workbook()<br>sheet = workbook.active<br><br># Create Data set in list<br>data = [<br>    (&#39;Product&#39;, &#39;Online Sales&#39;, &#39;Store Sales&#39;),<br>    (&#39;Laptop&#39;, 45, 30),<br>    (&#39;Smartphone&#39;, 70, 45),<br>    (&#39;Tablet&#39;, 35, 20),<br>    (&#39;Monitor&#39;, 40, 25),<br>    (&#39;Headphones&#39;, 50, 60),<br>]<br><br># Add data in worksheet<br>for row in data:<br>    sheet.append(row)<br><br># Create new bar chart<br>chart = BarChart()<br><br># chart.type: col = vertical, bar = horizontal<br># for bar chart, change the chart.type = &quot;bar&quot;<br>chart.type = &quot;col&quot;<br>chart.style = 5<br>chart.title = &quot;Product Sales Comparison&quot;<br>chart.y_axis.title = &quot;Units Sold&quot;<br>chart.x_axis.title = &quot;Product Category&quot;<br><br># default settings, can be removed if not required<br>chart.y_axis.delete = False<br>chart.x_axis.delete = False<br><br># Set data for the chart<br># min_col= 2, max_col= 3: This covers &quot;Online &amp; Stores Sales&quot;<br># min_row= 1, max_row= 6: This covers the headers, with 5 data rows<br>data_ref = Reference(sheet,min_col=2, max_col=3, min_row=1, max_row= 6)<br><br># min_col= 1: This is the &quot;Product&quot; column for the x-axis labels<br># min_row = 2: Not included the headers for the data<br>categories_ref = Reference(sheet,min_col=1, min_row=2 ,max_row= 6)<br><br># When add data, &quot;titles_from_data&quot; is set to be True as the <br># data_ref min row set to 1<br>chart.add_data(data_ref, titles_from_data=True)<br>chart.set_categories(categories_ref)<br><br># Add chart to worksheet<br>sheet.add_chart(chart, &quot;F2&quot;)<br><br># Save workbook<br>workbook.save(&quot;Column Chart.xlsx&quot;)</pre><h3>Create Line Graph</h3><ol><li>Create new workbook &amp; worksheet</li><li>Create data set in list</li><li>Add data to worksheet</li><li>Create new line chart</li><li>Add data to line chart</li><li>Add line chart to worksheet</li><li>Save workbook</li></ol><pre>import openpyxl<br>from openpyxl.chart import LineChart, Reference<br><br># Create new workbook and worksheet<br>workbook = openpyxl.Workbook()<br>sheet = workbook.active<br><br># Create data set in list<br>data = [<br>    (&#39;Product&#39;, &#39;Online Sales&#39;, &#39;Store Sales&#39;),<br>    (&#39;Laptop&#39;, 45, 30),<br>    (&#39;Smartphone&#39;, 70, 45),<br>    (&#39;Tablet&#39;, 35, 20),<br>    (&#39;Monitor&#39;, 40, 25),<br>    (&#39;Headphones&#39;, 50, 60),<br>]<br><br># Add data in worksheet<br>for row in data:<br>    sheet.append(row)<br><br># Create new line chart<br>chart = LineChart()<br>chart.title = &#39;Product Sales Comparison&#39;<br><br># Default settings, can be removed if not required<br>chart.y_axis.delete = False<br>chart.x_axis.delete = False<br><br># Add data to chart <br>data_ref = Reference(sheet, min_row=1, max_row=6, min_col=2,max_col=3)<br>categories_ref = Reference(sheet, min_row=2, max_row=6, min_col=1)<br><br>chart.add_data(data_ref,titles_from_data=True)<br>chart.set_categories(categories_ref)<br><br># Use the following code if to make the line straight<br>for series in chart.series:<br>    series.smooth = False<br><br># Add chart to worksheet<br>sheet.add_chart(chart, &quot;E2&quot;)<br><br># Save workbook<br>workbook.save(&quot;Line Chart Example.xlsx&quot;)</pre><h3>Create Scatter XY Graph</h3><ol><li>Load workbook</li><li>Create new scatter XY graph</li><li>Add data to graph</li><li>Add graph to worksheet</li><li>Save workbook</li></ol><pre>import openpyxl<br>from openpyxl.chart import ScatterChart, Reference, Series<br><br># Load worksheet with data to be plotted<br>wb = openpyxl.load_workbook(&quot;D-Wall Plot.xlsx&quot;)<br>ws = wb.active<br><br># Create scatter chart<br>chart = ScatterChart()<br><br>chart.title = &quot;D-Wall Plot&quot;<br>chart.x_axis.delete = False<br>chart.y_axis.delete = False<br>chart.legend = None<br><br>x_values = Reference(<br>    ws, <br>    min_row=2, <br>    max_row=len(df[&quot;Y [m] - exc S2&quot;]),<br>    min_col=2<br>)<br>y_values = Reference(<br>    ws, <br>    min_row=1, <br>    max_row=len(df[&quot;Y [m] - exc S2&quot;]),<br>    min_col=1<br>)<br><br>series = Series(y_values, x_values, title_from_data=True)<br>chart.scatterStyle = &#39;lineMarker&#39;<br><br># Use the following code if to make the line straight<br>series.smooth = False<br><br>chart.series.append(series)<br><br># Add chart to worksheet<br>ws.add_chart(chart, &quot;D2&quot;)<br><br># Save workbook<br>wb.save(&quot;D-Wall Plot.xlsx&quot;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4TgYtQPpyVFLQJCatWd22w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f652793bee3b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python and Excel with Openpyxl — 9]]></title>
            <link>https://medium.com/@lilacsol/python-and-excel-with-openpyxl-9-8feeebd890b8?source=rss-6bc48047d503------2</link>
            <guid isPermaLink="false">https://medium.com/p/8feeebd890b8</guid>
            <category><![CDATA[openpyxl]]></category>
            <category><![CDATA[excel]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[lilacsol]]></dc:creator>
            <pubDate>Fri, 20 Feb 2026 12:08:41 GMT</pubDate>
            <atom:updated>2026-02-27T00:31:14.045Z</atom:updated>
            <content:encoded><![CDATA[<h3>Import and Export data</h3><p>Example: Extract data in [m] and convert the data in [mm] and export to excel</p><ol><li>Import data using pandas</li><li>Select column data to be extracted, set it under a variable name for easy reference</li><li>Multiply each value stored under that variable to convert to mm</li><li>Option 1: Export the data at selected columns of the data frame</li><li>Option 2: Export the data at the last column of the data frame</li><li>Export the data to excel file</li></ol><pre>import openpyxl<br>import pandas as pd<br><br># Import data using pandas<br>df = pd.read_excel(&quot;merged plate.xlsx&quot;)<br><br># Create a new column for &quot;u_x [m] - exc S2&quot; with unit [mm]<br># i. Select and extract the column data, set it with a variable<br>u_x_S2 = df[&quot;u_x [m] - exc S2&quot;]<br><br># ii. Multiply each value stored under that variable with 1000 to convert <br># the value from [m] to [mm]<br>u_x_S2_mm = u_x_S2*1000<br><br># iii. Option 1: Insert the value created in ii. after <br># column &quot;u_x [m] - exc S2&quot;<br>df.insert(loc=6,column=&quot;u_x [mm] - exc S2&quot;,value=u_x_S2_mm)<br><br># iii. Option 2: Insert the value created in ii. at the end of the dataframe<br>df[&quot;u_x [mm] - exc S2 - end of column&quot;]=u_x_S2_mm<br><br># export the updated dataframe to excel<br>df.to_excel(&quot;Revised Merged Plate.xlsx&quot;,index=False)<br></pre><p>“Continue from above”</p><ol><li>Formula that can be applied to the variable: sum, mean, max, min</li><li>Load workbook and save the value back to worksheet</li></ol><pre># Example of formula can be applied to the column<br>u_x_S2.sum()<br>u_x_S2.mean()<br>u_x_S2.max()<br>u_x_S2.min()<br><br># can use sheet[&quot;cell location&quot;].value = u_x_S2.sum() to store <br># the value back to excel file<br>workbook = openpyxl.load_workbook(&quot;Revised Merged Plate.xlsx&quot;)<br>sheet = workbook.active<br>sheet[&quot;T2&quot;].value = u_x_S2.sum()<br>workbook.save(&quot;Revised Merged Plate.xlsx&quot;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4TgYtQPpyVFLQJCatWd22w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8feeebd890b8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python and Excel with Openpyxl — 8]]></title>
            <link>https://medium.com/@lilacsol/python-and-excel-with-openpyxl-8-2d9ee6258d8d?source=rss-6bc48047d503------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d9ee6258d8d</guid>
            <category><![CDATA[openpyxl]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[excel]]></category>
            <dc:creator><![CDATA[lilacsol]]></dc:creator>
            <pubDate>Thu, 19 Feb 2026 05:00:00 GMT</pubDate>
            <atom:updated>2026-02-27T00:31:39.943Z</atom:updated>
            <content:encoded><![CDATA[<h3>Set Border &amp; Cells Color</h3><ol><li>Create new workbook and worksheet</li><li>Set border style</li><li>Apply border style to cell number</li><li>Set fill type</li><li>Apply fill type to cell number</li><li>Save workbook</li></ol><pre>import openpyxl<br>from openpyxl.styles import Border, Side, PatternFill<br><br># Create new workbook and worksheet<br>workbook = openpyxl.Workbook()<br>sheet = workbook.active<br><br># style: {&#39;hair&#39;, &#39;dotted&#39;, &#39;mediumDashDot&#39;, &#39;slantDashDot&#39;, <br># &#39;mediumDashDotDot&#39;, &#39;double&#39;, &#39;thick&#39;, <br># &#39;dashDotDot&#39;, &#39;dashed&#39;, &#39;mediumDashed&#39;, &#39;dashDot&#39;, &#39;medium&#39;, &#39;thin&#39;}<br><br># Border Style<br>cells_border = Border(<br>    bottom=Side(style=&quot;thick&quot;),<br>    top=Side(style=&quot;dashDotDot&quot;, color=&quot;FF0000&quot;)<br>)<br><br># Apply border style to Cell B2<br>sheet[&quot;B2&quot;].border = cells_border<br>sheet[&quot;B2&quot;].value = &quot;Border Style&quot;<br><br># fill_type: {&#39;gray0625&#39;, &#39;mediumGray&#39;, &#39;darkGray&#39;, &#39;lightTrellis&#39;, <br># &#39;lightGrid&#39;, &#39;darkTrellis&#39;, &#39;darkVertical&#39;, <br># &#39;lightHorizontal&#39;, &#39;lightUp&#39;, &#39;lightGray&#39;, &#39;lightVertical&#39;, <br># &#39;darkGrid&#39;, &#39;lightDown&#39;, &#39;solid&#39;, &#39;gray125&#39;, <br># &#39;darkHorizontal&#39;, &#39;darkUp&#39;, &#39;darkDown&#39;}<br><br># Pattern Fill<br>pattern_fill = PatternFill(<br>    fill_type=&quot;darkDown&quot;,<br>    start_color = &quot;FF0000&quot;,<br>    end_color = &quot;FFFF00&quot;<br>)<br><br># Apply pattern fill to cell D2<br>sheet[&quot;D2&quot;].fill = pattern_fill<br>sheet[&quot;D2&quot;].value = &quot;Pattern Fill&quot;<br><br># Save workbook<br>workbook.save(&quot;Cell Border &amp; Fill.xlsx&quot;)</pre><h4>Similar to above, but set color to whole row in table</h4><ol><li>Create new workbook and worksheet</li><li>Create data in list</li><li>Add data to worksheet</li><li>Set fill type</li><li>Apply fill type to row of cell</li><li>Save workbook</li></ol><pre>import openpyxl<br>from openpyxl.styles import PatternFill<br><br># Create new workbook and worksheet<br>workbook = openpyxl.Workbook()<br>sheet = workbook.active<br><br># Create data in list<br>data = [<br>    (&#39;Product&#39;, &#39;Online Sales&#39;, &#39;Store Sales&#39;),<br>    (&#39;Laptop&#39;, 45, 30),<br>    (&#39;Smartphone&#39;, 70, 45),<br>    (&#39;Tablet&#39;, 35, 20),<br>    (&#39;Monitor&#39;, 40, 25),<br>    (&#39;Headphones&#39;, 50, 60),<br>]<br><br># Add data to worksheet<br>for row in data:<br>    sheet.append(row)<br><br># Pattern Fill<br>Fill_Color = PatternFill(<br>    start_color= &quot;FF0000&quot;,<br>    fill_type=&quot;solid&quot;<br>)<br><br># Apply pattern fill to row 3 of table<br>for cell in sheet[3]:<br>    cell.fill = Fill_Color<br><br># Save workbook<br>workbook.save(&quot;Table Row Color.xlsx&quot;)</pre><h4>BONUS: Using “enumerate” function to add each different fill type to each cell</h4><ol><li>Create new workbook and worksheet</li><li>Create list for fill type</li><li>Iterate through fill type list and set each of them to separate row</li><li>Save workbook</li></ol><pre># BONUS: <br><br>import openpyxl<br>from openpyxl.styles import PatternFill<br><br># Create new workbook and worksheet<br>workbook = openpyxl.Workbook()<br>sheet = workbook.active<br><br># Create list for fill type<br>list_filltype= [<br>    &#39;gray0625&#39;, &#39;mediumGray&#39;, &#39;darkGray&#39;, &#39;lightTrellis&#39;, &#39;lightGrid&#39;, <br>    &#39;darkTrellis&#39;, &#39;darkVertical&#39;, &#39;lightHorizontal&#39;, &#39;lightUp&#39;<br>]<br><br># Iterate through fill type list created and <br># set each of the fill type for different cell<br>for i, n in enumerate(list_filltype, start=1):<br>    pattern_fill = PatternFill(<br>        fill_type = n,<br>        start_color = &quot;FF0000&quot;,<br>        end_color = &quot;FFFF00&quot;<br>    )<br>    sheet[f&quot;D{i}&quot;].fill = pattern_fill<br>    <br>workbook.save(&quot;Fill Type_Cell.xlsx&quot;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4TgYtQPpyVFLQJCatWd22w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d9ee6258d8d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python and Excel with Openpyxl — 7]]></title>
            <link>https://medium.com/@lilacsol/python-and-excel-with-openpyxl-7-8de51b324c22?source=rss-6bc48047d503------2</link>
            <guid isPermaLink="false">https://medium.com/p/8de51b324c22</guid>
            <category><![CDATA[excel]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[openpyxl]]></category>
            <dc:creator><![CDATA[lilacsol]]></dc:creator>
            <pubDate>Wed, 18 Feb 2026 02:47:02 GMT</pubDate>
            <atom:updated>2026-02-27T00:32:27.176Z</atom:updated>
            <content:encoded><![CDATA[<h3>Formatting Text — Font Style &amp; Alignment</h3><ol><li>Create new workbook and worksheet</li><li>Define font style</li><li>Apply font style to cell number</li><li>Define text alignment</li><li>Apply text alignment to cell number</li><li>Save workbook</li></ol><pre>import openpyxl<br>from openpyxl.styles import Font, Alignment<br><br># Create new workbook and worksheet<br>workbook = openpyxl.Workbook()<br>sheet = workbook.active<br><br># Font Style<br>font = Font(<br>    name=&quot;Aptos&quot;,<br>    size=16,<br>    bold=True,<br>    italic=True,<br>    underline=&quot;single&quot;,<br>    strikethrough=True,<br>    color=&quot;FF0000&quot;,<br>)<br><br># Apply font style to Cell A1<br>sheet[&quot;A1&quot;].font = font<br>sheet[&quot;A1&quot;].value = &quot;Formatted Cell&quot;<br>sheet[&quot;A3&quot;].value = &quot;Unformatted Cell&quot;<br><br># Text Alignment<br>word_alignment = Alignment(<br>    horizontal = &quot;center&quot;,<br>    vertical = &quot;center&quot;,<br>    wrapText = True<br>)<br><br># Apply text alignment to Cell A1<br>sheet[&quot;A1&quot;].alignment = word_alignment<br><br># Save workbook<br>workbook.save(&quot;Formatting Text.xlsx&quot;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4TgYtQPpyVFLQJCatWd22w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8de51b324c22" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python and Excel with Openpyxl — 6]]></title>
            <link>https://medium.com/@lilacsol/python-and-excel-with-openpyxl-6-2e59bef77572?source=rss-6bc48047d503------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e59bef77572</guid>
            <category><![CDATA[openpyxl]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[excel]]></category>
            <dc:creator><![CDATA[lilacsol]]></dc:creator>
            <pubDate>Tue, 17 Feb 2026 02:43:44 GMT</pubDate>
            <atom:updated>2026-02-27T00:32:06.802Z</atom:updated>
            <content:encoded><![CDATA[<h3>Merge Cells</h3><ol><li>Create new workbook and worksheet</li><li>Merge selected cells</li><li>Save workbook</li></ol><pre>import openpyxl<br><br># Create workbook and worksheet<br>workbook = openpyxl.Workbook()<br>sheet = workbook.active<br><br># Merge selected cells<br>sheet.merge_cells(&quot;A1:D1&quot;)<br><br># Save workbook<br>workbook.save(&quot;Merge Cells.xlsx&quot;)</pre><h3>Unmerge Cells</h3><p>“Continue from previous worksheet”</p><ol><li>Unmerge selected cells</li><li>Save workbook</li></ol><pre># Continue from previous worksheet<br># Unmerge selected cells<br>sheet.unmerge_cells(&quot;A1:D1&quot;)<br><br># Save workbook<br>workbook.save(&quot;Merge Cells.xlsx&quot;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4TgYtQPpyVFLQJCatWd22w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e59bef77572" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python and Excel with Openpyxl — 5]]></title>
            <link>https://medium.com/@lilacsol/python-and-excel-with-openpyxl-5-41568da00ad2?source=rss-6bc48047d503------2</link>
            <guid isPermaLink="false">https://medium.com/p/41568da00ad2</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[openpyxl]]></category>
            <category><![CDATA[excel]]></category>
            <dc:creator><![CDATA[lilacsol]]></dc:creator>
            <pubDate>Mon, 16 Feb 2026 04:26:56 GMT</pubDate>
            <atom:updated>2026-02-27T00:33:15.271Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Insert Single Image</strong></h3><ol><li>Create new workbook and worksheet</li><li>Define image under variable</li><li>Optional: Adjust the image size</li><li>Insert image into worksheet</li><li>Save workbook</li></ol><pre>import openpyxl<br>from openpyxl.drawing.image import Image<br><br># Create new workbook and worksheet<br>workbook = openpyxl.Workbook()<br>sheet = workbook.active<br><br># Define Image under variable<br>img = Image(&quot;img1.png&quot;)<br><br># Resize Image<br>img.width = 200<br>img.height = 150<br><br># Insert Image into worksheet<br>sheet.add_image(img,&quot;A4&quot;)<br><br># Save workbook<br>workbook.save(&quot;Insert Image.xlsx&quot;)</pre><h3>Insert Multiple Image</h3><ol><li>Create new workbook and worksheet</li><li>Create list for multiple image</li><li>Optional: Adjust the image size</li><li>Insert image into worksheet</li><li>Save workbook</li></ol><pre>import openpyxl<br>from openpyxl.drawing.image import Image<br><br># Create new workbook and worksheet<br>workbook = openpyxl.Workbook()<br>sheet = workbook.active<br><br># Define Image - create list for multiple image<br>image_file = [&quot;img1.png&quot;,&quot;img2.png&quot;,&quot;img3.png&quot;]<br><br># Resize and insert image into worksheet<br>for i, value in enumerate(image_file,start=1):<br>    img=Image(value)<br>    img.height = 50 <br>    img.width = 50<br>    sheet.add_image(img,f&quot;A{i}&quot;) # because i value is int, hence use f-string method to combine<br><br>    # adjust row depth<br>    sheet.row_dimensions[i].height = 50<br><br># Save workbook<br>workbook.save(&quot;Insert Multiple Image.xlsx&quot;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4TgYtQPpyVFLQJCatWd22w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41568da00ad2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python and Excel with Openpyxl — 4]]></title>
            <link>https://medium.com/@lilacsol/python-and-excel-with-openpyxl-4-aff7fd5ef31b?source=rss-6bc48047d503------2</link>
            <guid isPermaLink="false">https://medium.com/p/aff7fd5ef31b</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[openpyxl]]></category>
            <category><![CDATA[excel]]></category>
            <dc:creator><![CDATA[lilacsol]]></dc:creator>
            <pubDate>Sun, 15 Feb 2026 07:10:42 GMT</pubDate>
            <atom:updated>2026-02-27T00:32:50.457Z</atom:updated>
            <content:encoded><![CDATA[<ol><li>Create new workbook and worksheet</li><li>Create data set in list</li><li>Iterate using “enumerate” to add each data into separate row into worksheet</li><li>Save workbook</li></ol><pre>import openpyxl<br><br># Create new workbook and worksheet<br>workbook = openpyxl.Workbook()<br>sheet = workbook.active<br><br># Data set in list<br>num = [4,9,30,57,89,104]<br><br># Iterate to add each data into separate row in worksheet<br># where i = index for each value<br># n = value in data list<br>for i, n in enumerate(num):<br>    sheet.cell(row= i+1,column=1,value= n)<br><br># Save workbook<br>workbook.save(&quot;Iterate Value.xlsx&quot;)</pre><ol><li>Create new workbook and worksheet</li><li>Create data set in list</li><li>Append data in worksheet</li><li>Option 1: Iterate and extract data as separate value</li><li>Option 2: Iterate and extract data into list</li><li>Save workbook</li></ol><p>To extract data from column, use alphabetical, example: “A”, “B”, “C”</p><p>To extract data from row, use numerical number, example: “1”, “2”, “3”</p><pre>import openpyxl<br><br># Create new workbook and worksheet<br>workbook = openpyxl.Workbook()<br>sheet = workbook.active<br><br># Data set in list<br>data = [<br>    (&#39;Product&#39;, &#39;Online Sales&#39;, &#39;Store Sales&#39;),<br>    (&#39;Laptop&#39;, 45, 30),<br>    (&#39;Smartphone&#39;, 70, 45),<br>    (&#39;Tablet&#39;, 35, 20),<br>    (&#39;Monitor&#39;, 40, 25),<br>    (&#39;Headphones&#39;, 50, 60),<br>]<br><br># Append data into worksheet<br>for row in data:<br>    sheet.append(row)<br><br># Option 1: Iterate and extract data from Column &quot;A&quot;<br>for cell in sheet[&quot;A&quot;]:<br>    print(cell.value)<br><br># Option 2: Iterate and extract data from Column &quot;A&quot; in list<br>value = [cell.value for cell in sheet[&quot;A&quot;]]<br>print(value)<br><br># Option 1a: Iterate and extract data from Row 2:<br>for cell in sheet[&quot;2&quot;]:<br>    print(cell.value)<br><br># Save workbook<br>workbook.save(&quot;Iterate Value_Column.xlsx&quot;)</pre><p>“Continue from example above using iter_rows”</p><ol><li>Option 1: Iterate all rows and extract each value</li><li>Option 2: Iterate all rows and extract the values in each rows in list</li></ol><pre># continue from previous worksheet<br><br># Option 1: Iterate all rows in worksheets and extract each value<br>for row in sheet.iter_rows(values_only=True):<br>    for value in row:<br>        print(value)<br><br># Option 2: Iterate all rows in worksheets and extract the values in list<br>for row in sheet.iter_rows(values_only=True):<br>    print(row)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4TgYtQPpyVFLQJCatWd22w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aff7fd5ef31b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python and Excel with Openpyxl — 3]]></title>
            <link>https://medium.com/@lilacsol/python-and-excel-with-openpyxl-3-6ca9a2cc061c?source=rss-6bc48047d503------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ca9a2cc061c</guid>
            <category><![CDATA[openpyxl]]></category>
            <category><![CDATA[excel]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[lilacsol]]></dc:creator>
            <pubDate>Sat, 14 Feb 2026 08:03:22 GMT</pubDate>
            <atom:updated>2026-02-27T00:34:08.642Z</atom:updated>
            <content:encoded><![CDATA[<ol><li>Create new workbook and worksheet</li><li>Option 1: Add value to cell using cell reference</li><li>Option 2: Add value to cell using row and column number</li><li>Save workbook</li></ol><pre>import openpyxl<br><br># Create new workbook and worksheet<br>workbook = openpyxl.Workbook()<br>sheet = workbook.active<br><br># Option 1: Add value to cell using cell reference <br>sheet[&quot;A1&quot;].value = &quot;Cell A1&quot;<br><br># Option 1: Add value to cell using row and column number<br>sheet.cell(row=1,column=2,value=&quot;Cell B1&quot;)<br><br># Save workbook<br>workbook.save(&quot;Insert Data.xlsx&quot;)</pre><ol><li>Create new workbook and worksheet</li><li>Create data in list</li><li>Append datalist into worksheet</li><li>Save workbook</li></ol><pre>import openpyxl<br><br># Create new workbook and worksheet<br>workbook = openpyxl.Workbook()<br>sheet = workbook.active<br><br># Data Set<br>data = [<br>    (&#39;Product&#39;, &#39;Online Sales&#39;, &#39;Store Sales&#39;),<br>    (&#39;Laptop&#39;, 45, 30),<br>    (&#39;Smartphone&#39;, 70, 45),<br>    (&#39;Tablet&#39;, 35, 20),<br>    (&#39;Monitor&#39;, 40, 25),<br>    (&#39;Headphones&#39;, 50, 60),<br>]<br><br># Append data into worksheet<br>for row in data:<br>    sheet.append(row)<br><br># Save workbook<br>workbook.save(&quot;Append DataList.xlsx&quot;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4TgYtQPpyVFLQJCatWd22w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ca9a2cc061c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python and Excel with Openpyxl — 2]]></title>
            <link>https://medium.com/@lilacsol/python-and-excel-with-openpyxl-2-4bc11411a0f7?source=rss-6bc48047d503------2</link>
            <guid isPermaLink="false">https://medium.com/p/4bc11411a0f7</guid>
            <category><![CDATA[openpyxl]]></category>
            <category><![CDATA[excel]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[lilacsol]]></dc:creator>
            <pubDate>Thu, 12 Feb 2026 13:56:40 GMT</pubDate>
            <atom:updated>2026-02-27T00:34:33.114Z</atom:updated>
            <content:encoded><![CDATA[<ol><li>Create new workbook and worksheet</li><li>Change sheet title</li><li>Add value to cell</li><li>Save workbook</li></ol><pre>import openpyxl<br><br># Create new workbook and worksheet<br>workbook = openpyxl.Workbook()<br>sheet = workbook.active<br><br># Change sheet title<br>sheet.title = &quot;Change Sheet Title&quot;<br><br># Add value to cell<br>sheet[&quot;A1&quot;].value = &quot;Hello&quot;<br><br># Save workbook<br>workbook.save(&quot;Change Sheet Title.xlsx&quot;)</pre><ol><li>Create new workbook and worksheet</li><li>Create multiple sheet</li><li>Add value to cell (for multiple sheet)</li><li>Save workbook</li></ol><pre>import openpyxl<br><br># Create new workbook<br>workbook = openpyxl.Workbook()<br><br># Create multiple sheet<br>sheet1 = workbook.create_sheet(&quot;Sheet A&quot;)<br>sheet2 = workbook.create_sheet(&quot;Sheet B&quot;)<br><br># Add value to cell <br>sheet1[&quot;A1&quot;] = &quot;1st sheet&quot;<br>sheet2[&quot;A1&quot;] = &quot;2nd sheet&quot;<br><br># Save workbook<br>workbook.save(&quot;Multiple Sheet.xlsx&quot;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4TgYtQPpyVFLQJCatWd22w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4bc11411a0f7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>