Python: Append a row to the end of an (.xlsx) document












0















Objective:
Appending a row to an (.xlsx) document using python (3.7).



What I wish to append to the last row of Document.xlsx. (cell delimiter: " | "):



(Last_Row): [Tom] | [Tablet] | [003332] | [Returned] | [PSEA]


Document.xlsx:



 [  A  ] | [   B   ] | [   C   ] | [    D   ] | [    E   ]
1: [FIID:] | [Device:] | [Gov_ID:] | [ Status ] | [Project:]
2: [John ] | [Laptop ] | [002435 ] | [Resigned] | [ AWSD ]
...
+4,000 rows


What I have so far is appending from a (.csv) document.



Pulling_Data_CSV.py



import csv

df = pd.read_csv(r"C:...Test_Pandas.csv")

with open(r"C:...Test_Pandas.csv", "a",newline="") as
csvfile:
writer = csv.writer(csvfile)
writer.writerow(["Tom", "Laptop", "003332", "Returned", "AWSD"])


What is the equivalent for editing a (.xlsx) document?



If that is not possible, how would I convert a (.xlsx) to (.csv), append a row, then convert it back to a (.xlsx) document?










share|improve this question





























    0















    Objective:
    Appending a row to an (.xlsx) document using python (3.7).



    What I wish to append to the last row of Document.xlsx. (cell delimiter: " | "):



    (Last_Row): [Tom] | [Tablet] | [003332] | [Returned] | [PSEA]


    Document.xlsx:



     [  A  ] | [   B   ] | [   C   ] | [    D   ] | [    E   ]
    1: [FIID:] | [Device:] | [Gov_ID:] | [ Status ] | [Project:]
    2: [John ] | [Laptop ] | [002435 ] | [Resigned] | [ AWSD ]
    ...
    +4,000 rows


    What I have so far is appending from a (.csv) document.



    Pulling_Data_CSV.py



    import csv

    df = pd.read_csv(r"C:...Test_Pandas.csv")

    with open(r"C:...Test_Pandas.csv", "a",newline="") as
    csvfile:
    writer = csv.writer(csvfile)
    writer.writerow(["Tom", "Laptop", "003332", "Returned", "AWSD"])


    What is the equivalent for editing a (.xlsx) document?



    If that is not possible, how would I convert a (.xlsx) to (.csv), append a row, then convert it back to a (.xlsx) document?










    share|improve this question



























      0












      0








      0








      Objective:
      Appending a row to an (.xlsx) document using python (3.7).



      What I wish to append to the last row of Document.xlsx. (cell delimiter: " | "):



      (Last_Row): [Tom] | [Tablet] | [003332] | [Returned] | [PSEA]


      Document.xlsx:



       [  A  ] | [   B   ] | [   C   ] | [    D   ] | [    E   ]
      1: [FIID:] | [Device:] | [Gov_ID:] | [ Status ] | [Project:]
      2: [John ] | [Laptop ] | [002435 ] | [Resigned] | [ AWSD ]
      ...
      +4,000 rows


      What I have so far is appending from a (.csv) document.



      Pulling_Data_CSV.py



      import csv

      df = pd.read_csv(r"C:...Test_Pandas.csv")

      with open(r"C:...Test_Pandas.csv", "a",newline="") as
      csvfile:
      writer = csv.writer(csvfile)
      writer.writerow(["Tom", "Laptop", "003332", "Returned", "AWSD"])


      What is the equivalent for editing a (.xlsx) document?



      If that is not possible, how would I convert a (.xlsx) to (.csv), append a row, then convert it back to a (.xlsx) document?










      share|improve this question
















      Objective:
      Appending a row to an (.xlsx) document using python (3.7).



      What I wish to append to the last row of Document.xlsx. (cell delimiter: " | "):



      (Last_Row): [Tom] | [Tablet] | [003332] | [Returned] | [PSEA]


      Document.xlsx:



       [  A  ] | [   B   ] | [   C   ] | [    D   ] | [    E   ]
      1: [FIID:] | [Device:] | [Gov_ID:] | [ Status ] | [Project:]
      2: [John ] | [Laptop ] | [002435 ] | [Resigned] | [ AWSD ]
      ...
      +4,000 rows


      What I have so far is appending from a (.csv) document.



      Pulling_Data_CSV.py



      import csv

      df = pd.read_csv(r"C:...Test_Pandas.csv")

      with open(r"C:...Test_Pandas.csv", "a",newline="") as
      csvfile:
      writer = csv.writer(csvfile)
      writer.writerow(["Tom", "Laptop", "003332", "Returned", "AWSD"])


      What is the equivalent for editing a (.xlsx) document?



      If that is not possible, how would I convert a (.xlsx) to (.csv), append a row, then convert it back to a (.xlsx) document?







      python excel pandas csv openxlsx






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 '18 at 15:45







      Quantum Nebula

















      asked Nov 13 '18 at 15:43









      Quantum NebulaQuantum Nebula

      53




      53
























          2 Answers
          2






          active

          oldest

          votes


















          0














          Here's an example using openpyxl:



          import openpyxl

          filename = 'C:\temp\spreadsheet.xlsx'
          wb = openpyxl.load_workbook(filename=filename)
          sheet = wb['Sheet1']
          new_row = ['column1', 'column2', 'column3']

          sheet.append(new_row)
          wb.save(filename)





          share|improve this answer



















          • 1





            Works flawlessly! Thank you! Now I got to add a border to the appended row, but I can look that up in the documentation for openpyxl

            – Quantum Nebula
            Nov 13 '18 at 16:14



















          0














          xlsx is a complex container format, based on xml. You could parse that yourself, but likely you want to check out a module like openpyxl and go from there.






          share|improve this answer
























          • Looking up the documentation for openpyxl, thank you. pointed me into the right direction.

            – Quantum Nebula
            Nov 13 '18 at 16:19











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53284571%2fpython-append-a-row-to-the-end-of-an-xlsx-document%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Here's an example using openpyxl:



          import openpyxl

          filename = 'C:\temp\spreadsheet.xlsx'
          wb = openpyxl.load_workbook(filename=filename)
          sheet = wb['Sheet1']
          new_row = ['column1', 'column2', 'column3']

          sheet.append(new_row)
          wb.save(filename)





          share|improve this answer



















          • 1





            Works flawlessly! Thank you! Now I got to add a border to the appended row, but I can look that up in the documentation for openpyxl

            – Quantum Nebula
            Nov 13 '18 at 16:14
















          0














          Here's an example using openpyxl:



          import openpyxl

          filename = 'C:\temp\spreadsheet.xlsx'
          wb = openpyxl.load_workbook(filename=filename)
          sheet = wb['Sheet1']
          new_row = ['column1', 'column2', 'column3']

          sheet.append(new_row)
          wb.save(filename)





          share|improve this answer



















          • 1





            Works flawlessly! Thank you! Now I got to add a border to the appended row, but I can look that up in the documentation for openpyxl

            – Quantum Nebula
            Nov 13 '18 at 16:14














          0












          0








          0







          Here's an example using openpyxl:



          import openpyxl

          filename = 'C:\temp\spreadsheet.xlsx'
          wb = openpyxl.load_workbook(filename=filename)
          sheet = wb['Sheet1']
          new_row = ['column1', 'column2', 'column3']

          sheet.append(new_row)
          wb.save(filename)





          share|improve this answer













          Here's an example using openpyxl:



          import openpyxl

          filename = 'C:\temp\spreadsheet.xlsx'
          wb = openpyxl.load_workbook(filename=filename)
          sheet = wb['Sheet1']
          new_row = ['column1', 'column2', 'column3']

          sheet.append(new_row)
          wb.save(filename)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 13 '18 at 15:56









          adambroadambro

          787




          787








          • 1





            Works flawlessly! Thank you! Now I got to add a border to the appended row, but I can look that up in the documentation for openpyxl

            – Quantum Nebula
            Nov 13 '18 at 16:14














          • 1





            Works flawlessly! Thank you! Now I got to add a border to the appended row, but I can look that up in the documentation for openpyxl

            – Quantum Nebula
            Nov 13 '18 at 16:14








          1




          1





          Works flawlessly! Thank you! Now I got to add a border to the appended row, but I can look that up in the documentation for openpyxl

          – Quantum Nebula
          Nov 13 '18 at 16:14





          Works flawlessly! Thank you! Now I got to add a border to the appended row, but I can look that up in the documentation for openpyxl

          – Quantum Nebula
          Nov 13 '18 at 16:14













          0














          xlsx is a complex container format, based on xml. You could parse that yourself, but likely you want to check out a module like openpyxl and go from there.






          share|improve this answer
























          • Looking up the documentation for openpyxl, thank you. pointed me into the right direction.

            – Quantum Nebula
            Nov 13 '18 at 16:19
















          0














          xlsx is a complex container format, based on xml. You could parse that yourself, but likely you want to check out a module like openpyxl and go from there.






          share|improve this answer
























          • Looking up the documentation for openpyxl, thank you. pointed me into the right direction.

            – Quantum Nebula
            Nov 13 '18 at 16:19














          0












          0








          0







          xlsx is a complex container format, based on xml. You could parse that yourself, but likely you want to check out a module like openpyxl and go from there.






          share|improve this answer













          xlsx is a complex container format, based on xml. You could parse that yourself, but likely you want to check out a module like openpyxl and go from there.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 13 '18 at 15:45









          BerserkerBerserker

          552415




          552415













          • Looking up the documentation for openpyxl, thank you. pointed me into the right direction.

            – Quantum Nebula
            Nov 13 '18 at 16:19



















          • Looking up the documentation for openpyxl, thank you. pointed me into the right direction.

            – Quantum Nebula
            Nov 13 '18 at 16:19

















          Looking up the documentation for openpyxl, thank you. pointed me into the right direction.

          – Quantum Nebula
          Nov 13 '18 at 16:19





          Looking up the documentation for openpyxl, thank you. pointed me into the right direction.

          – Quantum Nebula
          Nov 13 '18 at 16:19


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53284571%2fpython-append-a-row-to-the-end-of-an-xlsx-document%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Bressuire

          Vorschmack

          Quarantine